I designed and built a solar light controller. Back when I designed the controller I did not have the forethought of using one one my 4 PWM pins as the control pin for the light.
Now I want to at least add PWM to conserve battery life. I really don't want to redesign and re-fabricate the whole board. It is working great as is.
So I figured I could big bang the PWM for the current pin. I figure I don't need any kind of accuracy, I probably don't need to worry about a frequency. I just need to toggle the light off and on. Is this a good assumption?
The question is how to do the PWM.
One way I thought was to have a bit map.
1010101010101010
would give me 50% duty cycle.
In my main loop I would simply look at each bit one at a time, and either turn the light off or on.
So would
1001001001001001
give me a 37.5 duty cycle?
1000100010001000 = 25% duty cycle
and so on?
Now I want to at least add PWM to conserve battery life. I really don't want to redesign and re-fabricate the whole board. It is working great as is.
So I figured I could big bang the PWM for the current pin. I figure I don't need any kind of accuracy, I probably don't need to worry about a frequency. I just need to toggle the light off and on. Is this a good assumption?
The question is how to do the PWM.
One way I thought was to have a bit map.
1010101010101010
would give me 50% duty cycle.
In my main loop I would simply look at each bit one at a time, and either turn the light off or on.
So would
1001001001001001
give me a 37.5 duty cycle?
1000100010001000 = 25% duty cycle
and so on?