Hello guys,
i use the code below to steer my DC motor (with H-bridge and bootstrap circuit) with Atmega328 and it works fine for me, but i would like to turn off the pwms/timer1 on one side of the bridge (PIN 9 and 10) after short time (for example 2 secs) of being on. any thoughts how to do it ? I tried to reset TCCR1B after 2 secs standard delay() but it didn’t work for me (seems like timer just ignore delay and everything after it).
#include <avr/io.h>
void InitPorts1(void)
{
DDRB |= (1 << PB1) | (1 << PB2);
DDRD |= (1 << PD6) | (1 << PD5);
}
void InitTimer1(void)
{
TCNT1 = 0;
TCCR1A |= (1 << COM1A1) | (1 << COM1B1) | (1 << COM1B0);
ICR1 = 65000;
TCCR1B |= (1 << WGM13);
OCR1A = 22250;
OCR1B = 22400;
}
void StartTimer1(void)
{
digitalWrite(5, LOW);
delayMicroseconds(100);
digitalWrite(6, HIGH);
TCCR1B |= (1 << CS11) | (1 << CS10);
}
int main(void)
{
InitPorts1();
InitTimer1();
StartTimer1();
while (1)
{
}
}
And what’s more the code doesn’t work properly when i put it in standard void setup and void loop configuration of ArduinoIDE. When the code is in main function diodes on Pins 9 and 10 blinks alternately and the one on Pin 6 stays on, but when i put them in setup and loop version diodes on Pin 9 and Pin 6 stays on and the one attached to Pin 10 is off. What’s wrong ?