• Hello,
    I need to drive 16 independent pwm outputs + 3 analog inputs with the Pico, so I did a little test-setup, which is mostly working fine, but when sending a value (e.g. 0.1) to pin B15 and then send another value to A10, B15 is turned off. Sending 0 or 1 works as expected.
    I now found in the reference, that B15 is TIM1_CH3N and A10 is TIM1_CH3, whatever this means.
    Is there any way I can use both pins without interferencing each other?

    Thanks in advance.
    Marc

  • I'm afraid there isn't a way to use those two separately - they both use the same hardware, it's just that one is a negated version of the other one.

    You should hopefully be able to find a set of pins that don't share the same TIMx_CHy part?

    Or... How fast/accurate do you need the PWM to go? You can still use software PWM on pins that are tricky with something like analogWrite(pin, 0.5, { freq: 100, soft:true }).

  • Thanks for your quick answer. The PWM is just for LED dimming, so it doesn't be very acurate.
    What do you mean with "tricky"? Can B15 and A10 both be used by using software PWM?

  • And what about pins like B1, that list 2 different PWM channels?

  • Ok, perfect - so software PWM would be fine then (you can use it on absolutely any pins, so you could have B15 as software and A10 as hardware and everything would be great). You can even make several software PWM, but the more you have and faster you go, the more CPU is used.

    By 'tricky', I mean where you have them using the same timer channel.

    Where more than one channel is listed, you just have to look at the first one. While the hardware can handle multiple channels in that case, Espruino doesn't provide you with a way to specify which one you want to use.

  • Hey Gordon,

    thanks, this really works great, I now run 3 pins as software pwm (had to force it).
    Would be nice to replace those negated PWMs with real PWM channels on the pins that can do both. No idea, what those negated channels may be good for.

    Best regards,
    Marc

  • Would be nice to replace those negated PWMs with real PWM channels on the pins that can do both.

    Yeah, it would be - unfortunately that's all down to ST who make the chips, not me ;)

    I think the negated PWM exists for certain things where you want to use exactly the same PWM but get a normal and inverted output of the same thing at the same time.

  • Ah, I thought pins like B1 can be either TIM1_CH3N or TIM3_CH4.
    Thanks again :)

  • Sorry, I misread - yes, that could be done in software where the pins support both. Definitely B1 should be using TIM3_CH4

    A7 is more tricky, as if that used TIM3_CH2, it would conflict with B5! So you'll never be able to use B13, A7 and B5 at once - it's just a hardware restriction.

  • Hey Gordon,

    I finally did all the coding for my 16 channel PWM, now there are a few hiccups left so solve.
    To understand what I'm doing: I control 16 LED stripes from my espruino pico, that fade in one by one and after a little wait they fade out again.
    13 pins are hardware PWM and 3 are software only.
    I use setInterval with an interval of 15 to trigger the fading function, which increases the pwm value of the current channel and then analogWrites that value to the pin.
    If the pin is software then I do
    analogWrite(pin, value, { freq: 600, soft:true, forceSoft:true });
    I tried different frequencies, but 600 seems like a good compromise, with lower values the fading flickers and with higher values all lighted soft-PWM pins flicker when changing the value of one soft-PWM pin.
    But even with a value of 600 sometimes when fading in another soft-PWM pin, the others flicker and once in a while one of the other soft-PWM pins turns off completely for a short amount of time and then turns on again (without any software sending a new value to that pin).

    Any idea how this may be solved? Or is a freqency of 600 on 3 pins too much for the CPU to handle?

    Thanks in advance,
    Marc

  • Regarding inverted PWM: ...how abut having a full H-Bridge? ...driving some steppers could be a use for that... Two of those PWMs with 50% duty cycle and phase shift of 25% makes a perfect driver for two coil micro-steppers.

  • I think the problem might be that when you change a software PWM value, it basically cancels the old PWM and then starts a new one - so you can get 'glitches' (the hardware handles this automatically and avoids it). The faster the frequency the less obvious the glitches are, but then the more work Espruino is having to do.

    As you're doing your interval at 15ms, so 66 fps, you probably wouldn't see flicker if you just pulsed the pins at that rate.

    How about replacing:

    analogWrite(pin, value, { freq: 600, soft:true, forceSoft:true });
    

    with a set of:

    digitalPulse(pin1, 1, value1*15);
    digitalPulse(pin2, 1, value2*15);
    digitalPulse(pin3, 1, value3*15);
    

    You might find you could use setInterval with a period of 10 (and then set 15 to 10 above as well), and that could make a be compromise?

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

Pico: Why is B15 working against A10 when pwm-ing?

Posted by Avatar for Marc @Marc

Actions