Properties of Timers 2, 3, 4, and 5
Valid pins for PWM analogWrite:
analogWrite(A4,0.1,{ freq : 10 });
ERROR: Pin A4 is not capable of PWM Output
Suitable pins are:
A0 A1 A2 A3 A6 A7(AF) A8 A9 A10
A11 B0(AF) B1(AF) B3(AF) B4(AF) B5(AF) B6 B7 B8
B9 B10(AF) B11(AF) B13 B14 B15 C6(AF) C7(AF) C8(AF)
C9(AF)
Or pins with DAC output are:
A4 A5
You can also use analogWrite(pin, val, {soft:true}) for Software PWM on this pin
=undefined
Note the AF notation AF = Alternate Function
Using the attached file isTimerEnabled1.js and modifying the analog Write statements
Timer 5 uses pins:
A0, A1, A2, A3 or AF pins
Timer 4 uses pins:
B6, B7, B8, B9 or AF pins
Timer 3 uses pins:
A6, A8, A9, A10 or AF pins B4, B5, B0
Timer 2 uses pins:
Or AF pins B3, B10, B11.
Pins B1, A7, B13, B14, B15, C6, C7, C8, C9 are not seen by timers 2, 3, 4, or 5 when
used in a PWM analog Write statement.
When isTimerEnabled1.js is used with the following analogWrite commands,
While the duty cycles of pins A0, A1, A2, and A3 can be independently altered, they must all use the same frequency. The frequency is that of the last invoked analogWrite PWM command.
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.
Properties of Timers 2, 3, 4, and 5
Valid pins for PWM analogWrite:
Note the AF notation AF = Alternate Function
Using the attached file isTimerEnabled1.js and modifying the analog Write statements
Timer 5 uses pins:
A0, A1, A2, A3 or AF pins
Timer 4 uses pins:
B6, B7, B8, B9 or AF pins
Timer 3 uses pins:
A6, A8, A9, A10 or AF pins B4, B5, B0
Timer 2 uses pins:
Or AF pins B3, B10, B11.
Pins B1, A7, B13, B14, B15, C6, C7, C8, C9 are not seen by timers 2, 3, 4, or 5 when
used in a PWM analog Write statement.
When isTimerEnabled1.js is used with the following analogWrite commands,
Note the CCR1 thru CCR4 reflect the different duty cycles specified in the analogWrite commands.
If the analog Write commands are changed to
Note that CCR1 is non zero but CCR2, CCR3, and CCR4 are zero.
The program PWMflash.js looks for pulses divides them and flashes the red LED.
I used this to test the PWM properties.
While the duty cycles of pins A0, A1, A2, and A3 can be independently altered, they must all use the same frequency. The frequency is that of the last invoked analogWrite PWM command.
2 Attachments