wangine
Joined: 07 Jul 2009 Posts: 98 Location: Curtea de Arges, Romania
|
Low PWM without stress timer |
Posted: Tue Nov 17, 2015 12:51 pm |
|
|
I see here and on internet also many issues trying to get low frequency PWM, of course without stress timer. The function was made trying to get 1Hz PWM with normal duty 0-100.
Code: |
// ~~~~~~~~~~~~~~~~~~~~~once at n ms~~~~~~~~~~~~~~~~~~~~~~
#define pwm_pin PIN_x // output PWM pin
#define duty_min 1
#define duty_max 100
void timer_pwm(unsigned int8 duty)
{
if(pwm_period <= duty_min)
output_high(pwm_pin);
if(pwm_period == duty)
output_low(pwm_pin);
if(pwm_period >=duty_max)
pwm_period = 0;
} |
duty is actual state of PWM between 1-100%
Code: |
int8 pwm_period = 0;
#INT_TIMER1
void TIMER1_isr(void)
{
timer_pwm(open_duty);
pwm_period++;
} |
Each one can set a timer on any low frequency need. Example, at 10ms timer set, 10*pwm_period=1000 => 1Hz frequency PWM with variable duty. The function can update in any other functions. Also can be easy set any duty limits. |
|