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.

[SOLVED] motor control with atmega8

Status
Not open for further replies.

nishat anjum khan

Member level 2
Joined
Aug 4, 2012
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,562
i want to control a car with atmega8...but when i want left the motor run and move all time..but i want it will turn 90 degree angle and then go forward..here is my code and design..plz help
 

Attachments

  • motor.rar
    10.7 KB · Views: 59

Use the pullups in the input port and connect the buttons to ground, then it is just a matter of the logic you want to implement

Code:
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    DDRC = 0b11111111;
    PORTC = 0b00000000;
    DDRB = 0b00000000;
	PORTB = 0b00011111;
    while(1)
    {


        if ((PINB & (1<<0)) == 0)
        {
            PORTC = 0b00000101;
            _delay_ms(50);
        }

        else if ((PINB & (1<<1)) == 0)
        {
            PORTC = 0b00001001;
            _delay_ms(50);
            PORTC = 0b00000101;
        }
        else if ((PINB & (1<<2)) == 0)
        {
            PORTC = 0b00000100;
            _delay_ms(20);
            PORTC = 0b00000101;
        }
        else if ((PINB & (1<<3)) == 0)
        {
            PORTC = 0b00000001;
            _delay_ms(20);
            PORTC = 0b00000101;
        }
        else if ((PINB & (1<<4)) == 0)
        {
            PORTC = 0b00000000;
            _delay_ms(50);
        }
    }
}

Also make sure that you set the clock freq. in the project properties of AVR studio so that delays are calculated properly
 
i changed all things that u said and it simulates correctly...but when i do it in hardware always one motor is rotating and nothing happens when i press push button...what can i do now? what is the value of pullup register?
 

There is o need for external resistor, the internal pull up works fine
 

then i don't need to connect any resister with atmega in hardware?? i made some change in clock freq of avr and download it in microcontroller for hardware...now is it necessary to connect crystal oscillator with it?
 

When a pin is set as input and you set the PORT bit to 1 then the pullup for this pin is enabled, no need to use external circuits.
Did you connect your buttons to ground?

The default atmega clock source is internal RC , depending on the new source you have selected you may need to connect external clock or crystal I don't know what you did.
Did you change the CKSEL fuses?

Here is a fuse calculator https://www.engbedded.com/fusecalc
 

What do you mean by "i only change freq at avr", how did you do that?

If you mean the clock setting in the project then it doesn't change the clock speed, it is just used to calculate the delays so if it is wrong you will get wrong delays.
 

yup..i change the clock settings in the project..does it mean..i have to change anything for hardware?
 

The project setting doesn't change the core speed , it is just a variable that you set to the real value so don't use wrong values, there is no point.
 

actually this is my first project with microcontroller..so i have very small idea about it..thank u..i hope it will work
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top