The concepts are not 100% new to me because I've used Pi hats like this one https://www.pololu.com/product/2756 from Pololu and they have some startup code in python that's easy to learn. But that's based on using a Linux OS.
I am back to the Broadcom Peripherals Manual https://www.raspberrypi.org/app/uploads ... herals.pdf
And this good article on PWM https://www.embedded.com/electronics-bl ... Modulation
Also spent time looking at the WiringPi library's code and the RPIO code and even found this very simple and straight forward implementation in C++ https://gist.github.com/aboarya/94f836f ... m-cpp-L384
The information I've gathered so far is:
Looking at the below code, a couple of things I still dont get1) PWM Mode 0 can be enabled on GPIO pins 12 and 18, which map to Pi pins 32 and 12 on the board respectively
2) PWM0 aka MSEN0 can be used on channels 1 and 2, using the RNG1 and DAT1 registers for channel 1 and RNG2 and DAT2 for channel 2
3) Bits 0 and 1 of the CTL register enable and set the mode for channel 1
4) Bits 8 and 9 of the CTL register enable and set the mode for channel 2 ; the manual's CTL register table has a misprint here as best I can tell
5) The RNGi registers can be used to set the period, in MSEN0 this is the M in N/M
6) The DATi register can be used to set the N in the N/M for MSEN0
7) N and M here can be unsigned integers
Code: Select all
//set divisor *(clk + PWMCLK_DIV) = 0x5A000000 | (this->divisor << 12);
Finally, I am looking for guidance on good heuristics about the PWM formula in terms of a DC motor. Let's assume I want to power up a small DC motor to drive a single wheel of small robot car with a 9V battery.1) The C++ code sets the PWM Clock Divisor. I couldn't find any info in the manual on this:
2) What is the clock register and what is this value ? 0x5A000000
3) What is the clock divisor?
4) Where can I find this info on the Broadcom BCM2835 and/or other Pi's? I could not even find the CLOCK's base address
What are good choices for the frequency such that changing the duty cycle percentage in the value of DAT1 will change the speed of the robot in a **reasonable way?