Author Topic: Temperature Comparator  (Read 6123 times)

0 Members and 1 Guest are viewing this topic.

Offline seanhazTopic starter

  • Contributor
  • Posts: 12
  • Country: nz
Temperature Comparator
« on: October 03, 2013, 07:43:00 am »
Hey,
Im an Electrical Engineering student and still in my first year of study so im still pretty new to everything.

I want to build a circuit that compares the temperature of two temperature sensors and gives a variable PWM output to a motor to adjust the speed and also for it to run off solar powered with a small battery backup.

i have attached my circuit diagram i have created, Im using two LM35 temperature sensors giving signals into a ATtiny85 microcontroller in which i will write my program that will give a variable PWM signal depending of the temperature difference of the two sensors.

is there anything you suggest i should change? or anything im missing?

any advice is very welcomed.
 

Offline Andreas

  • Super Contributor
  • ***
  • Posts: 3222
  • Country: de
Re: Temperature Comparator
« Reply #1 on: October 03, 2013, 07:55:27 am »
is there anything you suggest i should change? or anything im missing?

any advice is very welcomed.

I would place a additional 100nF directly at the ATTiny at the power pins.
The motor return line should go directly to the battery and not across the ATTiny + sensor lines.

How long are the sensor lines? Eventually you will need further decoupling capacitors for the sensors + input low pass filtering for the ADC-inputs.

With best regards

Andreas
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Temperature Comparator
« Reply #2 on: October 03, 2013, 08:22:02 am »
1. you need a logic level mosfet;
2. gate resistors too big.
3. solar panel shorted by the battery.
...

this is soething a 555 + two ptc/ntc sensors could do
================================
https://dannyelectronics.wordpress.com/
 

Offline seanhazTopic starter

  • Contributor
  • Posts: 12
  • Country: nz
Re: Temperature Comparator
« Reply #3 on: October 03, 2013, 08:31:03 am »
I would place a additional 100nF directly at the ATTiny at the power pins.
The motor return line should go directly to the battery and not across the ATTiny + sensor lines.

How long are the sensor lines? Eventually you will need further decoupling capacitors for the sensors + input low pass filtering for the ADC-inputs.

With best regards

Andreas


thanks for the reply,

is the extra 100nF cap at the ATtiny to give it a more stable voltage?
and routeing the motor directly to the battery due to interference?

the sensor lines will be 2-3meters
 

Offline seanhazTopic starter

  • Contributor
  • Posts: 12
  • Country: nz
Re: Temperature Comparator
« Reply #4 on: October 03, 2013, 08:37:47 am »
1. you need a logic level mosfet;
2. gate resistors too big.
3. solar panel shorted by the battery.
...

this is soething a 555 + two ptc/ntc sensors could do

thanks for your reply,

I thought the FQP30N06L was a logic level mosfet?
what size resistors do you recommend?
 

Offline codeboy2k

  • Super Contributor
  • ***
  • Posts: 1836
  • Country: ca
Re: Temperature Comparator
« Reply #5 on: October 05, 2013, 01:53:59 am »
1. you need a logic level mosfet;
2. gate resistors too big.
3. solar panel shorted by the battery.
...

this is soething a 555 + two ptc/ntc sensors could do

thanks for your reply,

I thought the FQP30N06L was a logic level mosfet?
what size resistors do you recommend?

The FQP30N06L turns on at max 2.5V Vgs but it's not fully enhanced until around 10V Vgs.  A logic-level FET would be fully enhanced (or fully depleted) at 5V Vgs or less. 

However, this part should work fine at 5V Vgs, it achieves an R(ds)on of about 45 mOhms, which is comparable to a logic level FET anyways.

The 2.4k gate resistor limits the gate current to about 2mA, which saves your micro output drivers, but it's not enough current to switch the FET on very fast... According to the datasheet, that FET needs about 20nC of total gate charge to turn on at 5V Vgs.  1C is 1A in 1s .. thus 20nC is 20nA in 1s ... but you have 2mA available through the 2.4k gate resistor, so that would be 20nC/2mA = 10uS .. and taking 10uS to switch on is way, way too slow for PWM at the typical PWM frequencies above audio... like 25khz or 50khz..

The ATTINY85 can source max 40mA from each pin, up to a maximum of 200mA from all pins... 20nC/40mA = 500nS to fully charge the gate at Vgs = 5V.  To get 40mA of gate charging current, you need the gate resistor between 120 - 150 ohms.  Now, you can probably go lower than this, to say 100 ohms, and this will switch harder and faster, and the ATTINY will still see an average of less than 40mA at the pin, so long as you are less than 100% duty cycle on the PWM.  I didn't do the math for anything less than 120 ohms to figure out the max safe PWM duty cycle to keep the average current sourced out of the pin less than 40mA.

So I'd make R2 be from 120 to 150 ohms.

Just remember , it's the gate charging time that determines the switching time, and the switching time limits your PWM capabilities. If you want 10% minimum voltage, and your PWM frequency is 25kHz, then your PWM cycle time is 40uS. 10% is 4uS on time.  So you want to be fully on for 4uS, and thus want to reach that full-on level in less than 4uS, an order of magnitude less, so that would be 400ns.  In this case, 500ns is ok at the bottom end.

So, at a PWM frequency of 25kHz, you will want to size your gate resistor to achieve the charging current you need to reach a 400-500ns switching speed. If you use a faster PWM frequency, then you will need to switch faster still. Your post didn't mention what PWM frequency you will be using.

Sorry for the lengthy post.. I could have just said use a 150 ohm resistor and be done, but then you wouldn't know why to use it, nor how to change it if you wanted to. "Teach a person to fish" and all that...

« Last Edit: October 05, 2013, 02:00:05 am by codeboy2k »
 

Offline seanhazTopic starter

  • Contributor
  • Posts: 12
  • Country: nz
Re: Temperature Comparator
« Reply #6 on: October 05, 2013, 06:00:13 am »
1. you need a logic level mosfet;
2. gate resistors too big.
3. solar panel shorted by the battery.
...

this is soething a 555 + two ptc/ntc sensors could do

thanks for your reply,

I thought the FQP30N06L was a logic level mosfet?
what size resistors do you recommend?

The FQP30N06L turns on at max 2.5V Vgs but it's not fully enhanced until around 10V Vgs.  A logic-level FET would be fully enhanced (or fully depleted) at 5V Vgs or less. 

However, this part should work fine at 5V Vgs, it achieves an R(ds)on of about 45 mOhms, which is comparable to a logic level FET anyways.

The 2.4k gate resistor limits the gate current to about 2mA, which saves your micro output drivers, but it's not enough current to switch the FET on very fast... According to the datasheet, that FET needs about 20nC of total gate charge to turn on at 5V Vgs.  1C is 1A in 1s .. thus 20nC is 20nA in 1s ... but you have 2mA available through the 2.4k gate resistor, so that would be 20nC/2mA = 10uS .. and taking 10uS to switch on is way, way too slow for PWM at the typical PWM frequencies above audio... like 25khz or 50khz..

The ATTINY85 can source max 40mA from each pin, up to a maximum of 200mA from all pins... 20nC/40mA = 500nS to fully charge the gate at Vgs = 5V.  To get 40mA of gate charging current, you need the gate resistor between 120 - 150 ohms.  Now, you can probably go lower than this, to say 100 ohms, and this will switch harder and faster, and the ATTINY will still see an average of less than 40mA at the pin, so long as you are less than 100% duty cycle on the PWM.  I didn't do the math for anything less than 120 ohms to figure out the max safe PWM duty cycle to keep the average current sourced out of the pin less than 40mA.

So I'd make R2 be from 120 to 150 ohms.

Just remember , it's the gate charging time that determines the switching time, and the switching time limits your PWM capabilities. If you want 10% minimum voltage, and your PWM frequency is 25kHz, then your PWM cycle time is 40uS. 10% is 4uS on time.  So you want to be fully on for 4uS, and thus want to reach that full-on level in less than 4uS, an order of magnitude less, so that would be 400ns.  In this case, 500ns is ok at the bottom end.

So, at a PWM frequency of 25kHz, you will want to size your gate resistor to achieve the charging current you need to reach a 400-500ns switching speed. If you use a faster PWM frequency, then you will need to switch faster still. Your post didn't mention what PWM frequency you will be using.

Sorry for the lengthy post.. I could have just said use a 150 ohm resistor and be done, but then you wouldn't know why to use it, nor how to change it if you wanted to. "Teach a person to fish" and all that...

Thank you very much for all that, you have made it very clear to me now.

Thanks
 

Offline Whuffo

  • Regular Contributor
  • *
  • Posts: 112
  • Country: ph
  • An American Living In Paradise
Re: Temperature Comparator
« Reply #7 on: October 05, 2013, 08:04:39 am »
Engineering isn't just designing a circuit that works - it also needs to be the most cost effective solution.

That ATTiny is superfluous; it's overkill for this job. You can do all you want with a 555 circuit for much less money.

Microcontrollers are handy and useful - but they're not the solution to every problem. If you find yourself wanting to stick one in to deal with an analog problem, back off and reconsider. Better yet, try to avoid using them unless absolutely necessary. You'll be surprised how often you can do the job without one.

I keep seeing that people here start looking for a solution for a problem by finding ways to get their favorite MCU to do it. That's not good engineering; solve the problem in the most direct and economical way for the win.
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Temperature Comparator
« Reply #8 on: October 05, 2013, 08:44:54 am »
They're a solution to a great many more problems than they used to be, and so cheap now that it's well worth getting over the idea that something else might be preferable for that reason. Most of the cost of either that MCU or a 555 timer is in packaging, handling, shipping and distributor margin - especially in small volumes.

MCUs still don't have the same wide voltage range support that analogue solutions can tend to have, but that's their main downside for this type of circuit IMHO.

Offline Jon86

  • Frequent Contributor
  • **
  • Posts: 526
  • Country: gb
Re: Temperature Comparator
« Reply #9 on: October 05, 2013, 09:32:33 am »
Im using two LM35 temperature sensors giving signals into a ATtiny85 microcontroller in which i will write my program that will give a variable PWM signal depending of the temperature difference of the two sensors.

Difference amplifier and 555 timer? If you're an engineering student it'll give you far more experience and knowledge building an analog circuit like that, rather than just typing out some simple code and not using standard chips.
Also, it'll be more reliable (brownouts etc) and you're less likely to damage the output pins on the 555 than the MCU. 200mA rather than 40 is going to make your life a lot easier.  :-+
Death, taxes and diode losses.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Temperature Comparator
« Reply #10 on: October 05, 2013, 10:44:52 am »
Nothing wrong with trying to solve it with a mcu - a good learning experience.
================================
https://dannyelectronics.wordpress.com/
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4208
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Temperature Comparator
« Reply #11 on: October 05, 2013, 11:13:07 am »
...not using standard chips...

8 bit MCUs are standard chips.

Learning how to use one correctly, and how to deal with the limitations you've mentioned, is (IMHO) much more valuable as a general learning experience than using one particular chip to solve one particular problem.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf