Re: PWM and MEMORY
Moral of the story is - things sometimes appear more complicated than they really are. Simply 2 or 3 lines of code solved this problem when to me for awhile it seemed like I had to address memory space in an external chip and constantly refresh that memory space every time I did a button push.
PICBASIC made it very simple.
My project was a lLED dimmer. I'm using a 12f683 to produce a pulse width modulated (PWM) signal from pin 5 that's constantly on. It drives a P channel FET that provides a +12V pulse to the anodes of LEDs in parallel - common ground on the cathodes. The FET is capable of driving up to 14 amps of current, though that's way overkill for this application. I have a pullup resistor on pin 3 to +5V, with reverse polarity protection in case the user puts +12V to that pin, blowing up the PIC. A button tied to ground connects to pin 3. When the button is pushed, it provides a low to pin 3 and my code adjusts the duty cycle of the PWM command. (pwm ledout,duty,HERTZ). I did not debounce the signal - maybe on next rev. I probably do not need to condition the PWM signal with a cap and resistor in this application.
What I ignored was that when the circuit is powered up it needed to remember what brightness the leds were at when it was powered down - you don't adjust your dash lights in your car every time you start it. (dumb of me to not think of this).
Create a variable for the value you want to store - do a READ command, first value on initial power up is $ff - 255 unless you force it to another desired number - in my case 128 for the duty cycle of my PWM pulse.
Then do a WRITE command to the internal EEPROM on the 12f683 after each button push. I'm only writing one number (word) to the register - so I'm not worried about space. (it does write to same location - right?). Writing after each button push did affect the leds constant on, so I adjusted the HERTZ variable to remove blinking.
Power cycle the PIC and the PIC reads the EEPROM with the READ command and viola, the LEDs are the same brightness as when the PIC was turned off..
Simple -
thanks everyone..
My dad never liked you...
Bookmarks