Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

HELP! DC-motor control with ATMEGA32 in C

Status
Not open for further replies.

rbproject

New Member
For a school project we wanted to proof the persistence of vision. My job is to write a programm in C to control a DC motor (I'm using a simple motor from an drill that works on a 12V battery). But after doing a lot of research on other stuff. My time is running out, and I haven't much experience in programming C jet. Because the lessons are just started.

This is what it must do. I want to control the motor with the PWM from a ATMEGA32. This with 4 buttons with a different speed assigned to.

Maybe someone can help me a bit. Or give me some usefull tips. I have less than a week left. And I am stressing out.

thanks in advance

This is the code what I've got so far. It comes trough the compiler (AVR Studio) but it doesn't work on my testboard. Maybe there are some errors I didn't find. So can someone take a look at it

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/sleep.h>

unsigned int pwm;

SIGNAL (SIG_OVERFLOW1)
{
	switch(PINA & 0b00001111){ 

		case 0x01 : 
		pwm = 256; 
		break; 

		case 0x02 : 
		pwm = 512; 
		break; 

		case 0x04 : 
		pwm = 768; 
		break; 

		case 0x08 : 
		pwm = 1023; 
		break; 

		default : 
		break; 
	} 
	OCR1A = pwm;
}

void ioinit (void)
{
   DDRA = 0x00;
   PORTA = 0xFF;
   TCCR1A = _BV (WGM10) | _BV (WGM11) | _BV (COM1A1); 
   TCCR1B = _BV (CS10);
   OCR1A  = 0;
   DDRD   = _BV (PD5);
   TIMSK  = _BV (TOIE1);
   sei ();
}

int main (void)
{
   
   ioinit ();
    for (;;)			
        sleep_mode();
   return (0);
}
 
i don't have any AVR skills, but i could help you in the H-bridge part if you want... or you'r going to use a ready H-bridge IC ?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top