Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmega128 Programming Problem

Status
Not open for further replies.

DragonKlavier

Newbie level 2
Joined
Feb 10, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
16
Hi.

Im trying to move 2 motors with an atmega128 microcontroller. The issue is that i cant change my ports values in execution time. Two results. If i dont call the reverse function, the motor never stops, and if i call reverse() Function, the motor stops, but it doesnt change the movement sense or the moovement speed.

Here my code:


Code:
#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 0; //Como la función no es void se regresa un 0
	
	
	return;
}





int main()
{
	
		int power = -40;
		
		int pA=1;
		int pB=2;
		int duration=20;
		
		motors(pA, pB, power, duration);
		
		return 0;
}
 

Your program never gets out if its while loops.
Do something like this:

While (i <5000)
{
//do your stuff
i++;
}
i = 0;


Not sure about the rest of the code, but try this out first, and see what happens.
 

Agree with the above comment and your function void motors(...) is void, why do you have the return; ?
 

Im so sorry...I forget one detail:
Code:
While(1) and While(something<something)
have the same effect".Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top