• Hi Gordon,

    We've been playing around with the PWM's and after resoldering our docking station because B4 and A6 don't like eachother, we encountered a new problem.

    We reduced it to this:

    firmware v1.73:

    reset();
    analogWrite(B4,0.5);  // works!
    analogWrite(B0,0.5);  // The LED on B4 is dark now??
    analogWrite(B4,0.5);  // works, both are on
    analogWrite(B0,0.5);  // The LED on B4 is dark now??
    

    Is this a hardware thing or is it in the firmware?

    Cheers!

  • Expected hardware limitation - they both use TIM3.

    Stay away from PWM on B4/B5 those pins are TIM3 channel 1 and 2. You get 3 choices with TIM3 - it can be on A6A7B0B1, or it can be on B4 and B5 (and the other two channels aren't available - on versions of the chip with more pins, I think they are), or on C6-9 (but C6-9 have better alternatives for PWM, so TIM3 shouldn't get used for them)

    A while ago, this was much worse, but Gordon cleaned it up, so I don't think any pairs of PWM pins fight anymore, except B4/B5, which conflict with A6-B1.

    Now I think what Espruino uses is:

    TIM1 is on A8/9/10 - but IIRC you need to do something to shove the serial off A9/10 to use it on those pins, because it defaults to having Serial1 there so you can use bluetooth with it.
    TIM1 is also used for B13/14/15 (using the negated channels) - so you can't do PWM on A8/9/10 and B13/14/15 at the same time.

    TIM2 is on B10/B11
    TIM3 is on A67,B01 (and it fights with B4/5 - these pins also have other really messy options for PWM, but they all conflict even worse than TIM3, so they're not used)
    TIM4 is on B6~9
    TIM5 is on A0-3
    TIM6 and 7 can only drive internal interrupts - they don't have any output compare pins.
    TIM8 is on C6-9 (these ca also use TIM3, but we don't want them to)

    One could argue that Espruino should try to fish around for a better PWM channel if possible (ie you try to do analogWrite(B4); analogWrite(B0), but had nothing on TIM1 or TIM8 to use a negated channel, it'd use that) - but I think this would make the conflicts that still occurred much, much harder to debug.

    i don't understand the specific behavior you're seeing where they're somehow both on, though.

  • Hi DrAzzy,

    At the moment I'm using 12 PWM's: B3,B4,B8,B9,A0,A1,B10,B1,B0,A3,A7,B11.

    If I'd move the B4 to A2, would that be OK then?

    Cheers!

  • Yeah, that should be good.

    It's just B4 or 5 with A6, A7, B0, or B1.
    B13~15 with A8~10 also may not work as expected.

    (Oh - also: if you're specifying the frequency, it has to be the same for all channels on each timer - so if you do 200hz on A0, A1/2/3 will also be 200hz)

  • Thanks for the answers @DrAzzy - yes, there's a bug open for trying to make the interpreter more intelligent about choosing timers, but you're still likely to hit problems. At least if it were smarter it would be able to tell you though.

    I'll add a note to the board's pinout page though that B4 and B5 aren't good PWM pins to use though.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Setting analogWrite on B0 sets any analogWrite value of B4 to 0

Posted by Avatar for Alex @Alex

Actions