Hello guys,
I am new at this forum and I want to make a simulation of 2 servos on a atmega328. The servos have a period of 20ms and the pulse is between 1-2ms.
I wrote the following code :
I would be really grateful to any help or comment.
I am new at this forum and I want to make a simulation of 2 servos on a atmega328. The servos have a period of 20ms and the pulse is between 1-2ms.
I wrote the following code :
- Code:
#include <avr/io.h>
#include <util/delay.h>
//internal clock 1Mhz in the settings
int main(void)
{
DDRB |= 0xFF;
TCCR1A |= 1<<WGM11 | 1<<COM1A1 | 1<<COM1A0 1<<COM1B1 | 1<<COM1B0;
TCCR1B |= 1<<WGM13 | 1<<WGM12 | 1<<CS10; //Prescaler=1,inverted, fast PWM,Mode 14
ICR1 = 19999;
while (1)
{
int i;
for(i=1000;i<=2000;i+100)
{
OCR1A = ICR1 - i;
OCR1B = ICR1 - i;
_delay_ms(100);
}
}
}
I would be really grateful to any help or comment.
Last edited by arcachofo on Fri Dec 24, 2021 2:46 am; edited 1 time in total (Reason for editing : Marked as solved (green color))