The DC2 peripheral controls the speed and direction of two brushed DC motors using the D7HB H-Bridge card. The motor speed signals are pulse width modulated (PWM) signals with a programmable PWM frequency and a duty cycle between 0 and 100 percent.
The DC2 peripheral requires the D7HB dual H-Bridge card,
Resources let you control each motor as well as set the PWM frequency. A watchdog timer can shutdown both motors if the host stops writing to the peripheral.
mode0, mode1 : mode of operation for the motor.
The mode is encoded as a single character with the codes assigned as follows:
b -- brake (power on default)
f -- forward
r -- reverse
c -- coast
speed0, speed1 : PWM 'ON' time as a percentage.
The speed resolution is 10 bits for PWM frequencies below 20 KHz. The speed resolution is 8 bits for a PWM frequency of 78 KHz. Reading this give the _current_ speed. Writing it sets the _target_ speed. Current speed is subject to the constraints of slow start and slow stop so the current speed and the target speed might not be the same. That is, when you read the speed you might not immediately get back what you wrote to it.
PWMfrequency : PWM frequency in Hertz.
The driver tries to assign a frequency as close as possible to the one specified. For example, a requested frequency of 12510 Hertz might result in an actual PWM frequency of 12500 Hertz. The PWM frequency is the same for both motors. The default PWM frequency is 20000 Hertz.
slow_start0, slow_start1 : Acceleration curve
The acceleration curve is a list of ten space separated integers representing the time (in milliseconds) between each 10 percent increase from 0 to 100 percent ON time. The following string shows how to specify a slow start that takes half a second to get to 50 percent power and three-quarters of a second to get from zero to full power:
dpset dc2 slow_start0 100 100 100 100 100 50 50 50 50 50The default value for slow_start is off to full power in zero milliseconds. That is, the default is to turn off slow start.
slow_stop0, slow_stop1 : Deceleration curve.
The deceleration curve is a list of ten space separated integers representing the time (in milliseconds) between each 10 percent decrease from 100 to 0 percent ON time. The following string shows a slow stop that takes half a second to get to 50% power and three-quarters of a second to get from full power to zero:
dpset cd2 slow_stop0 100 100 100 100 100 50 50 50 50 50The default value for slow_stop is full on to full off in zero milliseconds. That is, the default is to turn off slow stop.
watchdog : Timeout in milliseconds.
As a safety feature, the FPGA hardware can turn both motors off if there is no speed or mode update within the specified time. The time is specified in milliseconds and has a maximum value of 1500 milliseconds. The resolution of the watchdog timer is 100 milliseconds, and a value of zero turns off the timer. The default value is 300 milliseconds.
Set the PWM frequency to 20KHz, put both motors into forward mode, set the watchdog timer to 500 ms, and set the PWM percentage to both motors to 65 percent.
dpset dc2 PWM_Frequency 20000 dpset dc2 watchdog 500 dpset dc2 mode0 f dpset dc2 mode1 f dpset dc2 speed0 65 dpset dc2 speed1 65