Alright guys, I got my temperature sensor working and now I need some help with this bugger.
In my previous thread I was suggested to use the RFP3055LE MOSFET and then PWM the Gate pin of the MOSFET and it can be used to control the speed of a fan.
Saipan59 wrote:
This is a very nice explanation but I ran into a small problem. My PIC only has the ability to PWM one device!!! For my final project I will need to use 4/6 (didn’t decide yet) MOSFETs to control 4/6 different fans independently of each other.
Anyone have any suggestions of what I can do? Are there some sort of I2C PWM controllers out there that can PWM 4-6 different devices in a single package? I checked digikey but couldn’t find anything similar to what I need… Or at least what I think I need.
Is there a software method I can do PWM to 6 different pins, each with their own duty cycle? I know you can do PWM by having an on/off period but then I would need to have 6 blocks of code, correct? Or I can possibly have one block with an array and for loop to save some space!
I won’t have an interrupts left over, I think, since they will all be going toward my USB stuff.
So I am open for suggestions to what you guys think is the best method for me. In case you forgot what I am talking about:
I am trying to control the speed at which a 12v fan is spinning. I was told that I can PWM a MOSFET which will then regulate the output voltage to the fan.
I am using the PIC18F4550 with a 20MHz external crystal. The PIC is running at 48MHz. (I may possible use a dsPIC30F4011 or PIC18F4620. The 30F4011 does have 6 PWM motor controller built in. I may switch over to that dsPIC depending if I can find a good bootloader for it!)
the nice thing about this part of your application, specifically PWM’ing a fan or six, is there is no real time issue to be fought with. In other words the PWM frequency probably wants to be low, 10 to 25Hz, and how much resolution do you really need? 10 discrete speeds? 25? Let me throw out a concept and some numbers and you can see what you think, but don’t make any cracks about reading the essay after you’ve had something to eat or I’m done.
I’ll take the worst case to start, assume you need to generate a PWM pulse 25 times a second, and you want 25 levels of resolution for 6 fans. So 25Hz * 25 Steps = 625, so you need an interrupt every 1.6mS. If you “were” using the PWM then your PIC has a CCP module (PWM is part of the CCP module usually) and you can generate an interrupt from the CCP instead of toggling a pin. On the older PIC parts it was called CCP special event mode or something similar. So anyway, now when you get an interrupt you just need to maintain a counter and have the 6 PWM variables with values from 0 to 25. When the counter equals 0 you check each variable and turn it’s fan on if it’s non-zero. If the variable value is zero then the fan stays off. Now the next interrupt increment the counter to 1 and you check each variable for a 1, and for each variable equal to the counter you turn the respectvie fan off. Next interrupt increment the counter and repeat. Now when you increment the counter and it reaches 25 you reset it to zero and start over. Any variables that had a 25 (or more) in them the fans will stay on indefinately. Any value between 0 and 25 and the fan will be on that portion of a cycle (specifically 100% * (var / 25)). The interrupt has an increment, 7 equality compares, and as many as 14 port pin changes, so on a PIC it should take maybe 50 assembly instructions (outside any register state preservation you need to do in the ISR.)
yeah my point, although I didn’t explicitly say so, was that this is really easy to do in software. if you had already allowed for the timer / ccp / pwm resource in your PIC it is really easy to just use it to generate the required interrupt. If you read through my post carefully it should not be too difficult to build a flow chart from the step by step description I gave of the interrupt code steps.
Yup, I was talking with Nick earlier on AIM and he suggested to use a timer. He suggested how I can do it and gave me some example code. But his lady friend called him away so il figure out the rest. Thanks mates