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.

Need C code for Controlling Speed Of DC geared Motors in ATmega8

Status
Not open for further replies.

vivekanand2990

New Member
hey guyz...

i m making a project using ATMega8 in which
i want to control fully DC geared motors via Programming
eventually i m capable to switch ON and OFF the Motors but
can't know how to control the speed of DC motors.
By my Knowledge with Gadgets i can figure out
for doing the task that i should vary the motor supply voltage using PWM
(Pulse width Modulation). .....

but can't know how implement it using C code..

so plzz Help me its urgent ....the deadline for the project is very near...@@

Vivekanand !!
 

krich

New Member
Rather than do your homework for you, I'll give you a push in the right direction.

Basics:
look up H-bridge schematics
read datasheet for your MCU for built in PWM technology.
Tutorials on PWM at avrfreaks forums

More advanced:
read up on PID control.
Many motor control whitepapers on chip manufacturers websites (st.com comes to mind)
google for an article called "PID without a PHD". Good stuff.
 

tytower

Banned
Or you could go to arduino.cc ,download the IDE ,follow the guide and its all done for you already
 

abhinav229

New Member
i m doing a project of line follower robot which counts the number of colour transitions on its path.so please help me to write a program using atmega8 microcontroller
 

wkrug

Active Member
The ATMEGA 8 has some Hardware PWM Generators.
I think the best one for your usage ist the PWM of Timer 1.

Timer 1 has 2 PWM Generators that can give Signals on the Output OC1A and OC1B.
The resolution ist switchable from 8Bit up to 16Bit.

The Steps are following:
1. Initialize the Timer 1 for the wished PWM Mode and frequency, additional Connect the OC1A Output.
2. Calculate the Duty Cycle for your Motor.
3. Write the wished Duty Cycle while an Interrupt into OCR1A ( for PWM A ) and it will run.

How to do this, you can read in the Datasheet of ATMEGA8.
The PWM frequency can be tuned by clock frequency and prescaler of Timer 1
Do not use fast PWM Mode - In this Mode Duty Cycle 0% isn't possible!
Change values is to do in an Interupt of Timer 1 ( Timer Overflow Interrupt or Comparematch 1A Interrupt ), to avoid glitches.
Which of both Interrupts is to use appends from the used PWM Mode.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top