Using Poke to Do PWM on Pins A0, A1, A2, and A3
Before trying to configure a timer into other modes of operation using poke commands, it would be useful to configure a timer using a known configuration created by the command analogWrite(A0,0.2,{ freq : 50 });
A known configuration:
If we modify isTimerEnabled3.js lines 168 thru 172 to read:
The attached file PokeA0Timer5a.js contains the code to implement pins A0, A1, A2, A3 on timer 5 using poke commands. Note that either powering the board off or using the reset button will clear the timer settings.
First setup the pins for alternate function output:
//timer 5 clock
var RCCbase=0x40021000;
var APB1ENR=RCCbase+0x1c;
var APB1RST=RCCbase+0x10;
var APB2ENR=RCCbase+0x18;
//turn on timer 5 clock
poke8(APB1ENR,(peek8(APB1ENR)&0xf7)|0x08);
//reset timer 5
poke8(APB1ENR,(peek8(APB1RST)&0xf7)|0x08);
poke8(APB1ENR,(peek8(APB1RST)^0x08));
Note the frequency is determined by the ARR, and PSC registers and can be modified by the CR1 register.
Additionally the frequency depends on the clock chain see Figure 8 on page 92 of the RM0008 Reference manual. The register APB1 controls the prescaler for timers 2, 3 , 4, 5, 6, 7, 12, 13, and 14. The register APB2 controls the prescaler for timers 1, 8, 9, 10, and 11.
The CCMR1 and CCMR2 registers configure the CC (capture/compare) pins of the timer as output or input on one of three sources.
The CCER register configures the polarity and enable that connects to the pins A0..A3.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Using Poke to Do PWM on Pins A0, A1, A2, and A3
Before trying to configure a timer into other modes of operation using poke commands, it would be useful to configure a timer using a known configuration created by the command analogWrite(A0,0.2,{ freq : 50 });
A known configuration:
If we modify isTimerEnabled3.js lines 168 thru 172 to read:
The attached file PokeA0Timer5a.js contains the code to implement pins A0, A1, A2, A3 on timer 5 using poke commands. Note that either powering the board off or using the reset button will clear the timer settings.
First setup the pins for alternate function output:
Next turn timer 5 on and reset it
Finally configure timer 5 and enable it
Note the frequency is determined by the ARR, and PSC registers and can be modified by the CR1 register.
Additionally the frequency depends on the clock chain see Figure 8 on page 92 of the RM0008 Reference manual. The register APB1 controls the prescaler for timers 2, 3 , 4, 5, 6, 7, 12, 13, and 14. The register APB2 controls the prescaler for timers 1, 8, 9, 10, and 11.
The CCMR1 and CCMR2 registers configure the CC (capture/compare) pins of the timer as output or input on one of three sources.
The CCER register configures the polarity and enable that connects to the pins A0..A3.
1 Attachment