A.12. command 216: get average motor current, B. buzzer commands, Section 3.a.12 – Pololu Orangutan X2 User Manual

Page 11

Advertising
background image

losses, however the motor 1 PWM frequency is used for acceleration timing, so decreasing it below 1 kHz can
slightly reduce the frequency at which acceleration updates are performed (at the lowest frequency, acceleration
updates will occur every 13 ms instead of every 10 ms).The frequencies can be different for each motor so long
as the X2 isn’t being run in joint motor mode. In joint motor mode, both PWMs are set to based on the motor 1
PWM frequency settings.

This command does not save this setting to EEPROM, however it can be saved by issuing separate EEPROM-
write commands (240—

Section 3.d.02

) that store the values at the appropriate addresses (1 for motor 1, 2 for

motor 2). The EEPROM byte saved for a given motor should be set as follows: bit 2 high = 8-bit pwm resolution,
bit 2 low = 7-bit pwm resolution; bits 0 & 1 represent the PWM’s clock prescaler setting as detailed below.

The prescaler setting is encoded by a two-bit enumeration: 0 = prescaler 8, 1 = prescaler 64, 2 = prescaler 256,
and 3 = prescaler 1024. The resolution setting is a one-bit value: 0 = 7-bit PWM, 1 = 8-bit PWM.

The resulting PWM frequency can be calculated as 20MHz / prescaler / 2

bit-resolution

. The following PWM

frequencies (along with their three-bit encondings) can hence be achieved:

19.5 kHz (000)

=> 7-bit resolution, prescaler 8

9.77 kHz (100)

=> 8-bit resolution, prescaler 8

2.44 kHz (001)

=> 7-bit resolution, prescaler 64

1.22 kHz (101)

=> 8-bit resolution, prescaler 64

610 Hz (010)

=> 7-bit resolution, prescaler 256

305 Hz (110)

=> 8-bit resolution, prescaler 256

153 Hz (011)

=> 7-bit resolution, prescaler 1024

76.3 Hz (111)

=> 8-bit resolution, prescaler 1024

Values sent: motor 1 PWM resolution (1 bit), motor 1 PWM prescaler (2 bits), motor 2 PWM resolution (1 bit),
motor 2 PWM prescaler (2 bits)

command byte = 210

data byte = (motor 2 PWM resolution bit << 5) | (motor 2 PWM prescaler << 3) | (motor 1 PWM resolution bit
<< 2) | motor 1 PWM prescaler

3.a.12. Command 216: Get Average Motor Current

Effect: This command will cause the mega168 to load the eight most significant bits of the running ADC average
for the specified motor into its SPDR (SPI data register). Once loaded, sending another byte over the SPI will
load the value into the mega644’s SPDR. This second byte can be the NULL command (255—

Section 3.d.06

) or

merely a junk data byte (any byte so long as the MSB is zero). It is recommended you do not begin transmission
of this second byte until 3 us after the transmission of the command byte has completed. This is to make sure the
mega168 has time to load the SPDR.

Values sent: motor (1 bit)

command byte = 216 | motor bit

3.b. Buzzer Commands

Orangutan X2 Command Documentation v1.01

© 2001–2010 Pololu Corporation

3. Low-Level SPI Commands

Page 11 of 27

Advertising