Hi Gerard,
If you want to go easy you can simply use Arduino's analogWrite()
call, which accepts a value between 0 (always off) and 255 (always on)
for the duty cycle [1]. This is also the "fallback" in
DualMC33926MotorShield.cpp in case of a chip other than ATmega168/328P
(see [0]).
The disadvantage of this approach is that this runs at a very low
frequency, either 490 Hz or 980 Hz on Arduino Uno (see [1]).
You can get much higher (better) frequencies by manipulating the
Atmega's timer registers directly - and that is what
DualMC33926MotorShield.cpp will do when it finds an Atmega168/328P
chip - in that case it will use a frequency of about 20Khz.
This magic is configured as follows in DualMC33926MotorShield.cpp:
#if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
// Timer 1 configuration
// prescaler: clockI/O / 1
// outputs enabled
// phase-correct PWM
// top of 400
//
// PWM frequency calculation
// 16MHz / 1 (prescaler) / 2 (phase-correct) / 400 (top) = 20kHz
TCCR1A = 0b10100000;
TCCR1B = 0b00010001;
ICR1 = 400;
[...]
#if defined(__AVR_ATmega168__)|| defined(__AVR_ATmega328P__)
OCR1A = speed;
This is, by the way, what Pololu means with the following feature [4]:
"PWM operation up to 20 kHz, which is ultrasonic and allows for
quieter motor operation"
Hope that helps,
Kristof
[0]
https://github.com/pololu/dual-mc33926-motor-shield/blob/master/DualMC33926MotorShield/DualMC33926MotorShield.cpp
[1]
http://arduino.cc/en/Reference/AnalogWrite
[2]
http://arduino.cc/en/Tutorial/PWM
[3]
http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM
[4]
http://www.pololu.com/product/2503
> --
> You received this message because you are subscribed to the Google Groups
> "ros-by-example" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ros-by-exampl...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/ros-by-example.
> For more options, visit
https://groups.google.com/d/optout.