question about speed control

55 views
Skip to first unread message

Grinan Barrett

unread,
May 16, 2012, 1:08:30 AM5/16/12
to xaxxon...@googlegroups.com
Hi,

I am very interested in the oculus code and hardware going on here.. looks pretty cool.

I downloaded the .pde file and was looking at it to see what makes it tick.. I noticed that there are pin assignments for the enable pins on the hbridge, and that there are speed adjustments through the web interface.. but it doesn't look like the enable pins are ever written to by the code..

Are you actually using pwm to control speed? or on the controller board to you have the enable pins tied high so that the run without the pwm speed control? 

Just wondering.

Thanks
Grinan

XaxxonColin

unread,
May 16, 2012, 2:34:23 AM5/16/12
to xaxxon...@googlegroups.com
Hi Grinan,
It uses PWM but we had to set the ATmega PWM registers directly, since the 'stock' Arduino servo library PWM frequency of 500Hz didn't allow maximum power to the wheel's DC gearmotors. (The board and motors are ONLY powered by the max 2.5W power from the netbook's USB port, and this has to haul around the 2.5Kg total weight of the robot... so optimization was a necessity.)

We used the following code to set the 4 pins going to the H-bridge PWM frequency to a low 30Hz:

pinMode(motorA1Pin, OUTPUT);
pinMode
(motorA2Pin, OUTPUT);
pinMode
(motorB1Pin, OUTPUT);
pinMode
(motorB2Pin, OUTPUT);
TCCR2A
= _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20); // phase correct (1/2 freq)
TCCR2B
= _BV(CS22) | _BV(CS21) | _BV(CS20); // divide by 1024

Which allows us to thereafter set the speed of the left and right motors with:


OCR2A = 0; // 0-255, motor A duty cycle
OCR2B = 0; // 0-255, motor B duty cycle

This gave the motors much more torque at lower speed settings.
For fine control of PWM frequency, this resource helped: http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM, as did the detailed spec sheet for the ATmega chip.

Sellec

unread,
May 16, 2012, 4:51:13 AM5/16/12
to xaxxon...@googlegroups.com
>> since the 'stock' Arduino servo library PWM frequency of 500Hz didn't allow maximum power to the wheel's DC gearmotors. 
you mean, if i would set pin value with digitalWrite(Pin, 255), it would not be a maximum power?

XaxxonColin

unread,
May 16, 2012, 11:19:13 AM5/16/12
to xaxxon...@googlegroups.com
Actually "digitalWrite(Pin, 255)" WOULD be maximum power since it's 100% duty cycle and the frequency doesn't factor into it.  
Anything less, say 50% - digitalWrite(Pin, 128), would work, but it would be at the 'stock' frequency of 500MHz and the actual torque measured at the wheel is considerably lower than if PWM is cycled at 30Mhz. The power savings may be because the lower frequency allows the wheels to gain some rotational momentum between cycling on and off.

We used the same method for using PWM dimmer control in our firmware for the OcuLED Lights, but not for maximizing power reasons. The stock 500 MHz frequency didn't work at all--anything above 128 resulted in lights full ON and anything below was completely OFF.  We found 240Hz to be a happy medium to be able to finely-tune the brightness of the light, yet not notice any flicker.

Grinan Barrett

unread,
May 22, 2012, 5:03:47 PM5/22/12
to xaxxon...@googlegroups.com
Ok, so i get the gist of what you are doing.

So I have an arduino mega 1280 laying around, and for some reason this concept has just grabbed me. 

I tried to load your firmware on my 1280, mainly to see if I could get it to actually run my h-bridge and a gm8 motor from just my usb power.  It didn't work at all.    It does load, and when I start the oculus server, it actually reports that it is connected to the hardware.  But I get no motion from my motors at all.

Is there a major difference in the ports or timers for the 328 you are using and the 1280?   I would love to be able to use the pwm as you are doing.

Any help or links would be appreciated. 

XaxxonColin

unread,
May 22, 2012, 5:25:08 PM5/22/12
to xaxxon...@googlegroups.com
Yes the PWM registers on the ATmega1280 would likely be quite different from the 328, since the registers are pin-specific, and the 1280 has a different (larger) pin-set. Unless you can find the info on-line, you may have to go through the exercise of deciphering the info on the datasheet (PWM section starts on p118).

Reply all
Reply to author
Forward
0 new messages