SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By RossWaddell
#163438
I've been working on a project off-and-on for a while now that includes blinking LEDs and motor control (using PIC microcontrollers and PICBasic Pro). For the blinking LEDs, I want to be able to adjust the brightness which I've can do for non-blinking LEDs with PWM and a pot (in code: ADC to use pot input to vary duty cycle). For a blinking LED, though, it seems trickier and I haven't been able to get my head around it (I dabble in this stuff but I'm no electronics engineer). Can I use a single PIC (say, 12F1840) with a CCP module to have the code handle the blinking and the 'brightness' (i.e. duty cycle) be turned off and on by that port output? Do I need to daisy chain a 'FET or transistor?

Any help would be greatly appreciated.
By Mee_n_Mac
#163440
RossWaddell wrote: Can I use a single PIC (say, 12F1840) with a CCP module to have the code handle the blinking and the 'brightness' (i.e. duty cycle) be turned off and on by that port output?
Sure you can. Right now you have "blinking" code that sets a pin to turn on the LED, then counts some amount of time and then turns the LED off. Some other count is done and the the LED is turned on again. You have "non-blinking" code that sets the CCP to PWM mode and varies the duty cycle setting (according to a pot reading) to get different brightnesses for other LEDs. What you need to do is connect the blinking LED to a pin that can be PWM'ed, just as you've done for the non-blinking LEDs. If you needed a transistor to drive the LED(s) before, you'll need one now. Combine the 2 codes such that when the blinking LED is supposed to be on, the PWM setting is derived from the pot. The brightness of the blinking LED, when on, is now set by the pot, just like all the other non-blinking LEDs. Count as you presently do for the LED on time and then, when the LED is supposed to be off, change the PWM setting to be 0% duty cycle. That is set the brightness to fully dim, completely off. Count as you do for the off time and when the LED is supposed to be on, change the PWM setting back to the pot derived value. Wash, rinse, repeat.
By RossWaddell
#163441
Thanks Mee_n_Mac! That does seem quite straight forward although I wonder if there's any 'overhead' to changing to duty cycle to 'x%' (on) and then later to 0% (off) that might affect the overall timing of the blinking. The goal is to blink 2 LEDs at twice per second.