Temperature Comparator  - Page 1
Forum section: electronics / projects

author: seanhaz
author_rank: Contributor
timestamp: October 03, 2013, 07:43:00 am
content: 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.

author: Andreas
author_rank: Super Contributor
timestamp: October 03, 2013, 07:55:27 am
content: Quote from: seanhaz on October 03, 2013, 07:43:00 amI 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 regardsAndreas

author: dannyf
author_rank: Super Contributor
timestamp: October 03, 2013, 08:22:02 am
content: 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

author: seanhaz
author_rank: Contributor
timestamp: October 03, 2013, 08:31:03 am
content: Quote from: Andreas on October 03, 2013, 07:55:27 amthanks 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

author: seanhaz
author_rank: Contributor
timestamp: October 03, 2013, 08:37:47 am
content: Quote from: dannyf on October 03, 2013, 08:22:02 amthanks for your reply,I thought the FQP30N06L was a logic level mosfet?what size resistors do you recommend?

author: codeboy2k
author_rank: Super Contributor
timestamp: October 05, 2013, 01:53:59 am
content: Quote from: seanhaz on October 03, 2013, 08:37:47 amThe FQP30N06L turns on at max 2.5V Vgsbut it's not fully enhanced until around 10V Vgs. A logic-level FET would be fully enhanced (or fully depleted) at 5V Vgsor less.However, this part should work fine at 5V Vgs, it achieves an R(ds)onof 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...

author: seanhaz
author_rank: Contributor
timestamp: October 05, 2013, 06:00:13 am
content: Quote from: codeboy2k on October 05, 2013, 01:53:59 amThank you very much for all that, you have made it very clear to me now.Thanks

author: Whuffo
author_rank: Regular Contributor
timestamp: October 05, 2013, 08:04:39 am
content: 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.

author: AndyC_772
author_rank: Super Contributor
timestamp: October 05, 2013, 08:44:54 am
content: 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.

author: Jon86
author_rank: Frequent Contributor
timestamp: October 05, 2013, 09:32:33 am
content: Quote from: seanhaz on October 03, 2013, 07:43:00 amDifference 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.

author: dannyf
author_rank: Super Contributor
timestamp: October 05, 2013, 10:44:52 am
content: Nothing wrong with trying to solve it with a mcu - a good learning experience.

author: AndyC_772
author_rank: Super Contributor
timestamp: October 05, 2013, 11:13:07 am
content: Quote from: Jon86 on October 05, 2013, 09:32:33 am8 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.