First off, if B13~15 are listening to alternate device, they will get PWM output if any of the TIM1_CH*N outputs are enabled.
Same goes for A7,B0,B1 and TIM8_CH*N outputs.
Fine... except that when the Espruino firmware enables the non-negated output (bits 0, 4, 8), it also enables the negated output for the same channel (bits 2, 6, 10). Why does analogWrite(A8) set bits 0 and 2, instead of just bit 0?
Bit 2/6/10 in TIM1_CCER should only be set for TIM1 if PWM is desired on B13~B15, not when it is desired on A8~A10.
Bit 2/6/10 should never be set for TIM8_CCER, because those pins have better timer options - but even if we are going to use the TIM8_CH*N outputs, they should only be set when that output is required, not when the non-negated output is.
The second issue is the selection of the timers.
I tried to read build_pininfo.py, but I haven't the faintest what it's doing or how.
What it is clearly not doing is assigning the first timer on the list to each pin.
Based on experiment (setting analogWrite() and then peeking at appropriate registers), it looks like the timer used alternates between available timers on adjacent pins, maximizing the potential for conflicts.
analogWrite(A6) outputs on TIM3_CH1 (great!)
analogWrite(A7) outputs on TIM8_CH1N (not great!)
analogWrite(B0) outputs on TIM3_CH3 (great!)
analogWrite(B1) outputs on TIM8_CH3N (not great!)
analogWrite(A0) outputs on TIM5_CH1 (great!)
analogWrite(A1) outputs on TIM2_CH2 (not great!)
analogWrite(A2) outputs on TIM2_CH3 (not great!)
analogWrite(A3) outputs on TIM5_CH4 (great!)
analogWrite(C6) outputs on TIM3_CH1 (bad)
analogWrite(C7) outputs on TIM8_CH2 (good)
analogWrite(C8) outputs on TIM3_CH3 (bad)
analogWrite(C9) outputs on TIM8_CH4 (good)
This explains the conflicts noted above.
When C7 starts up TIM8_CH2, that plays ontop of what B0 is getting from TIM3_CH3, because TIM8_CH2N is also enabled.
(same with the other ones I originally called "linked").
Meanwhile the "mutually exclusive" ones were due to fighting over which bank to point timer 3 at.
Finally, analogWrite(A9) or analogWrite(A10) should shove the USART out of the way - but there's already an issue for this.
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.
Well, there are a few issues here
First off, if B13~15 are listening to alternate device, they will get PWM output if any of the TIM1_CH*N outputs are enabled.
Same goes for A7,B0,B1 and TIM8_CH*N outputs.
Fine... except that when the Espruino firmware enables the non-negated output (bits 0, 4, 8), it also enables the negated output for the same channel (bits 2, 6, 10). Why does analogWrite(A8) set bits 0 and 2, instead of just bit 0?
Bit 2/6/10 in TIM1_CCER should only be set for TIM1 if PWM is desired on B13~B15, not when it is desired on A8~A10.
Bit 2/6/10 should never be set for TIM8_CCER, because those pins have better timer options - but even if we are going to use the TIM8_CH*N outputs, they should only be set when that output is required, not when the non-negated output is.
The second issue is the selection of the timers.
I tried to read build_pininfo.py, but I haven't the faintest what it's doing or how.
What it is clearly not doing is assigning the first timer on the list to each pin.
Based on experiment (setting analogWrite() and then peeking at appropriate registers), it looks like the timer used alternates between available timers on adjacent pins, maximizing the potential for conflicts.
analogWrite(A6) outputs on TIM3_CH1 (great!)
analogWrite(A7) outputs on TIM8_CH1N (not great!)
analogWrite(B0) outputs on TIM3_CH3 (great!)
analogWrite(B1) outputs on TIM8_CH3N (not great!)
analogWrite(A0) outputs on TIM5_CH1 (great!)
analogWrite(A1) outputs on TIM2_CH2 (not great!)
analogWrite(A2) outputs on TIM2_CH3 (not great!)
analogWrite(A3) outputs on TIM5_CH4 (great!)
analogWrite(C6) outputs on TIM3_CH1 (bad)
analogWrite(C7) outputs on TIM8_CH2 (good)
analogWrite(C8) outputs on TIM3_CH3 (bad)
analogWrite(C9) outputs on TIM8_CH4 (good)
This explains the conflicts noted above.
When C7 starts up TIM8_CH2, that plays ontop of what B0 is getting from TIM3_CH3, because TIM8_CH2N is also enabled.
(same with the other ones I originally called "linked").
Meanwhile the "mutually exclusive" ones were due to fighting over which bank to point timer 3 at.
Finally, analogWrite(A9) or analogWrite(A10) should shove the USART out of the way - but there's already an issue for this.