So I have this DC motor which I want to reduce it's speed to 25% so obviously I used phase correct pwm to do so via the motor driver , I was able to do it through timer1 but my assistant professor wants me to do it with the 8-bit timer0 so I wrote the code and it ran but in full so my question is there are some calculation that must be done before writing the code and if there are , what are these calculations ?
Note : motor frequency is 100-250 Hz I am working with internal frequency 1 MHz and prescaler 1024
#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB = DDRB | (1<<PB3); //set OC0 as output pin --> pin where the PWM signal is generated from MC
/*set CS02:0 to 101 to work with 1024 prescaler
set WGM0[1:0] to 01 to work with phase correct,pwm
set COM01:0 to 11 to Set OC0 on compare match when up-counting. Clear OC0 on compare match
when downcounting*/
TCCR0 = 0b00111101;
OCR0 = 64; // 25% DUTY CYCLE
while (1)
{
;
}
}