I’ve got the two wired together (specifically the VNH5019), but have yet to implement the code… Will tackle that this coming weekend.
That said, does anyone know of existing implementations for this purpose? My current plan is to mix and match the existing servo.h/c code with that from another C library that I’ve used with a similar motor driver (Webbotlib + VNH3SP30)
A bit of searching didn’t find anything… so I’ll make sure to update when I have clean functioning code, and possibly go so far as to do a good enough job to put a pull request for my code into the Wixel SDK.
I’ve got this mostly working… however I’m stuck on doing the PWM. I really need to acquire/improvise an oscope one of these days.
I’m using a modified servo.c/h library for the PWM. This of course approximates the 50Hz 1-2ms PWM for servos. I understand the math that results in 19.11ms between leading edges of pulses, but… I can’t find where this is set? Can anyone point me to where in servo.c/h or elsewhere, that the frequency/duty cycle is set? Thanks!
I’ve done some digging into the cc2511f32 manual, but not had the chance to fully understand a ton…
Hello. There is no place in the code were we explicitly set a frequency or duty cycle, but those properties are a result of the Timer 1 settings we configure in servosStart and the code in the ISR. I have highlighted those parts of the code in the links below:
To understand the Timer 1 settings you will need to carefully read the appropriate section of the CC2511 datasheet. You shouldn’t need to use an ISR in your application; just write to the duty cycle registers whenever you want to change the motor speed.
An oscilloscope would definitely help. I think there are a lot of decent USB scopes and logic analyzers in the $100-$300 range, such as the one from this review on EEVBlog: eevblog.com/2013/03/09/eevbl … -teardown/
MOTOR = Typedef’d struct with PWM pin, and one or two direction pins
MOTOR_DRIVER = list of MOTORs (unused for my application) (limited to 2 motors; i.e. Wixel can run a single dual-motor driver board)
setMotorSpeed() receives a motor and speed, and sets direction pins, calculates duty cycle value in ticks, calls pwmSetTargetHighRes()
Speeds are given in range -127 to 127 (int8), and interpolated from 0 to duty cycle period in ticks to get “on” time in ticks. Will probably change this to -1000 to 1000 eventually.
PWM
Timer 1 in Modulo mode
Clear on compare-up, set on 0; Duty cycle is then T1CCn/T1CC0;
Set T1CC0 based on desired frequency as T1CC0 = 2.4e7[ticks/s] / (1/freq[Hz])
No interrupts/ISR
Possible PWM pins are P1_0 & P1_1, OR P0_3 & P0_4. (P0_2 and P1_2 are the two pins corresponding to channel 0 for Timer 1)
pwmStart() enforces the ‘OR’, setting the timer location and enabling the appropriate GPIO pins
Code is fairly clean and lives in MotorDriver.c/h. This code is then used in twitch_mx_xbee.c, which is not as clean. These files are located here: github.com/erelson/wixel-sdk/tr … ch_mx_xbee
If this is the sort of thing you would like to add to the Wixel SDK apps, I’d be glad to do further cleanup/changes. Let me know what needs fixing.