Have someone can share example ?
2005-02-18 by Luke.Wei
Yahoo Groups archive
Index last updated: 2026-04-28 22:41 UTC
Thread
2005-02-18 by Luke.Wei
Dear all
Have someone can share example about PWM or step motor
controller . thanks
Luke2005-02-19 by wbounce
For a atmega 128 gcc
void initmotor(void)
{
/* use fast PWM mode 10 bit with toggle on compare
Reference pages 130 table 58
Page 133 table 61
f OCn = f clk_I_O
-------------
N * (1 + TOP)
f clk_I_O = 16000000
Top can be either
ff ( 255) for mode 5
1ff ( 511) for mode 6
3ff (1023) for mode 7
prescales
Mode 1 8 64 256
1024
5 62500 7812.5 976.5 244.1 61
6 31250 3906.2 488 122 30
7 15625 1953 244 61 15
use mode 6 with 8 prescale
*/
// need to set TCCR3A register
// page 130
// TCCR3B register needs to look like bit 7 - 4 = 0 bit 3 = 1 bit 2 = 0
bits 1 =0 and bit 0 = 1
//ICNC3 ICES3 - WGM33 WGM32 CS32 CS31 CS30
// 0 0 0 0 1 0 0
1
// TCCR3A
//bit 7 6 5 4 3
2 1 0
//COM3A1 COM3A0 COM3B1 COM3B0 COM3C1 COM3C0 WGM31 WGM30
//1 0 1 0 0
0 1 1
// turn everything off
LeftEnable = 0;
RightEnable = 0;
TCCR3A = BV(WGM31); /* set timer/counter 3 to fast PWM mode 6 */
TCCR3A |= BV(COM3A1) | BV(COM3B1); /* Clear OCnA/OCnB/OCnC on compare
match when up-counting. */
TCCR3B = BV(CS31) | BV(WGM32) ; /* prescale: 8 @ 16 MHz, 10 bit PWM
overflows @ 1953 HZ */
// turn everything off
OCR3A= 0;
OCR3B= 0;
DDRE |= BV(PORTE3)|BV(PORTE4); /* enable PWM outputs */
// set these as output (pins 0 through 3 on port A)
DDRA |= BV(PORTA0) | BV(PORTA1) | BV(PORTA2) | BV(PORTA3) ;
}
To to forward I set the pins for direction and then this code sets the
speed to close to 100%
OCR3A = 500;
OCR3B = 500;
-- turns the motor off
OCR3A = 500;
OCR3B = 500;
There are other aspects about pwm control of motor that depend on the
hbridge-----Original Message-----
From: Luke.Wei [mailto:mrddt4todie@yahoo.com.tw]
Sent: Thursday, February 17, 2005 10:32 PM
To: AVR-Chat@yahoogroups.com
Subject: [AVR-Chat] Have someone can share example ?
Dear all
Have someone can share example about PWM or step motor
controller . thanks
Luke
Yahoo! Groups Links