parallaxinc / cyberbot

Firmware, library, and loader code for cyberbot hardware
MIT License
8 stars 0 forks source link

Finalize PWM functions #2

Open MatzElectronics opened 5 years ago

MatzElectronics commented 5 years ago

Implement PWM for GPIO and DA pins in Propeller firmware Confirm that API bot().write_analog() will work

MatzElectronics commented 5 years ago

Notes from D/A & PWM issue raised by @AndyLindsay: @MatzElectronics. Per our discussion, I developed and added dac2ch and pwm2ch libraries and examples to the Simple Libraries Demo (.zip) branch.

Examples are in ...SimpleIDE/Learn/Examples/Devices/Convert/ and they are also documented in ...SimpleIDE/Learn/Simple Libraries Index.html. Multiple cogs with up to 2 channels each are supported, and you can also set channels to input with -1 in the dacVal (dac2ch) and tHigh (pwm2ch) arguments.

IMPORTANT: PWM generates a sawtooth on the D/A0 and D/A1 ports, so please make sure to use the dac2ch library for D/A on those ports. It also has higher resolution updates in less time with 12.5 ns/lsb vs 1 us/lsb with PWM. The pwm2ch library would be better for slow-ish transistors in H bridges and the like, and other situations where duty cycle control is needed.

MatzElectronics commented 5 years ago

@AndyLindsay @tommygober @PropGit Ready for testing, please use Version 0.3.

Please test against published examples. Note that the servo_speed function now has additional parameters allowing for diff_drive-like behavior. This should help with the >3ms lag when the servos are called individually. We need to decide if the APi for that is appropriate, and possibly update all of the existing examples.

Question: Do we need to provide a function/method for changing the PWM frequency? It only provides for changing the PWM duty cycle currently.

Additionally, note that there are up to 4 "channels" of PWM available (except on pins 20 & 21, which have their own dedicated PWM) - please test that this works as expected, perhaps by connecting 5 or more LEDs - you should be able to set up to four, and when you set the 5th, it will use the "channel" that was assigned first. Also, calling any function that manipulates a pin will first disable PWM on that pin.