Hello, I was created this main file project. Whith this, I try to move 2 motors conected toa driver, and the driver to the Atmega128 Micro.
Im noob in this topics. The problem is that i cant change the motors (PortB or C in My program AT128) in execution time. In my code, the motor works only a seconds, and then it stop. The idea is that the motor should change speed and movement sense,
#include <avr/io.h>
#include <util/delay.h>
int cont=0;
void reverse()
{
while(1);
{
PORTC=0b01010101;
PORTD|=_BV(PD0); //Se activa el bit 0 del PORTD
PORTD|=_BV(PD1); //Se activa el bit 1 del PORTB
_delay_us(5000);
//de la función, con la variable SH, SH veces
PORTD&=~(_BV(PD0)); //Desactiva el bit 0 del PORTD
PORTD&=~(_BV(PD1)); //Desactiva el bit 1 del PORTB
_delay_us(5000);
}
}
void motors(int pA, int pB, int power, int duration)
{
//PORTC=0b10101010;
PORTC=0b01010101;
DDRC= 0xFF; //puerto C como salida
DDRD= 0xF0; //Nible alto del puerto D como salida
while (1)
{
PORTD|=_BV(PD0); //Se activa el bit 0 del PORTD
PORTD|=_BV(PD1); //Se activa el bit 1 del PORTB
_delay_us(9800);
//de la función, con la variable SH, SH veces
PORTD&=~(_BV(PD0)); //Desactiva el bit 0 del PORTD
PORTD&=~(_BV(PD1)); //Desactiva el bit 1 del PORTB
_delay_us(200);
//cont++;
}
reverse();
return;
}
int main()
{
int power = -40;
int pA=1;
int pB=2;
int duration=20;
motors(pA, pB, power, duration);
return 0;
}