Okada
Banned
I am using PIC12F1840. INTRC 4 MHz. I want variable frequency and variable duty PWM. Freq range is 9 Hz to 14 Hz and duty 0 to 100%.
Can I use Two Timers and a Pot to make Variable PWM ? or do I need Two timers and two pots ?
Pots are used for ADC. ADC value is converter to timer reload values.
I am planning to do like this.
1. Enable timer 0 and disable timer 1
2. Start Timer 0 for PWM ON period and port bit on from previous timer 1.
3. When Timer 0 interrupt occurs, stop timer 0 and turn off timer 0 and toggle port bit. Start timer 1 for pwm off period.
4. When timer 1 interrupt occurs stop timer 1, turn ON port bit, start timer 0.
repeat 2 to 4 continuously
Read adc value and convert raw adc value to timer 0 on time and timer 1 on time for pwm on and off times.
All suggestions are welcomed.
How many times the port bit turns ON and OFF in 1 sec determines the PWM frequency. Right ?
The duration of PWM On time and PWM Off time setermines the pwm duty. Right ?
Edit:
Single timer can be used.
The PWM On time and Off time timer relaod values are alternately loaded in the timer isr.
Can I use Two Timers and a Pot to make Variable PWM ? or do I need Two timers and two pots ?
Pots are used for ADC. ADC value is converter to timer reload values.
I am planning to do like this.
1. Enable timer 0 and disable timer 1
2. Start Timer 0 for PWM ON period and port bit on from previous timer 1.
3. When Timer 0 interrupt occurs, stop timer 0 and turn off timer 0 and toggle port bit. Start timer 1 for pwm off period.
4. When timer 1 interrupt occurs stop timer 1, turn ON port bit, start timer 0.
repeat 2 to 4 continuously
Read adc value and convert raw adc value to timer 0 on time and timer 1 on time for pwm on and off times.
All suggestions are welcomed.
How many times the port bit turns ON and OFF in 1 sec determines the PWM frequency. Right ?
The duration of PWM On time and PWM Off time setermines the pwm duty. Right ?
Edit:
Single timer can be used.
The PWM On time and Off time timer relaod values are alternately loaded in the timer isr.
Last edited: