PWM signals

Posted on
  • Hi,

    I want to use the Espruino for controling my hexapod robot. Therefore I need 18 PWM signals at one time. Until now I used an Atmega16 to simulate the PWM signals, but Espruino has enough hardware PWM outputs, so I thought of using it, instead of the microcontroller.

    Unfortunately I read, that there are only 6 timers for the PWMs and I didn't find anything of saying which timer should be used for which pin. So it seems to be random, if the PWM work or not.

    Is there any workarround, not simulating the PWM signals or is it impossible to control 18 PWM signals? What is the maximum of working PWM together, only 6 like timers, less or more?

    P.S.: I also read something about PWMs dont working together, but it seems that there are enough outputs to avoid this problem.

    Thank you!

  • At the moment you can use most PWM outputs at once - while you can't choose the timers yourself, Espruino tries to pick timers that don't overlap. Sometimes there are problems though and I'm afraid at the moment the best solution is really just to test.

    While there are only 6 timers, each timer has 4 outputs which can run at the same frequency (but different duty cycles). For servo control you'll be running them all at the same frequency though so you should be fine, and you should be able to get 18 servos running from some combination of pins.

    Having said all that, Espruino uses one of the timers as a 'utility' timer, so calls to 'digitalPulse' work really well on any pin (and are non-blocking). That's what I tend to use for Servo control and it's what I'd suggest you use for starters - especially as I guess the duty cycle will be changing for almost every pulse if you're trying to get nice smooth movement.

  • You can see which timers can be on each pins looking at the espruino board reference.

    I think you should be able to scrape together enough PWM pins for that project.

    Each timer can do 4 outputs (usually)

    Ones that I know work reliably: You have C6~9, A0~A3, B6~B9 B10+B11 are all definitely OK. That's 14 right there.

    I think - but am not sure - that Gordon has set it up so A6~B1 now always use TIM3 and hence don't fight with other timers. Too late for me to check tonight.
    If so, that's your 18.

    A8 works, and A9+10 can be made okay with that poke command (see the other thread you referred to).

    And B3 of course works.

    That would also get you the 18 you needed, even if none of the middle 4 are usable (and I think they are usable now anyway - so you've got 4 extra PWM channels )

    B13~B15 are no good for you, though - they can only output the negation of TIM1, and they overlap the SD card pins anyway!

  • Hi,

    thanks for yur replies. I will try your suggestions and tell, if it works or not.

  • If I use something like analogWrite(A0, 0.5). What is the default frequency of the PWM's?

  • As far as I know it depends on the device and which timer you're using - it'll be in the kHz range I believe.

  • Okay, reason for asking is that I need a low pass filter for the PWM.
    Used 100K and 0.1uF RC filter which appears to do the job for the kit its connected to but I don't have a scope to test how clean it is.

  • Well, if you have any specific requirements for frequency then I'd just do something like analogWrite(A0, 0.5, {freq:10000}) rather than relying on default values.

    And you know there are two proper analog DAC outputs on the chip as well?

    By the way, you can get something like a DSO Nano for around £40 now if you want a cheap way to look at signals. I use an HPS140 which is quite similar, and often pull it out in preference to a proper bench scope if I need to check something quickly.

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

PWM signals

Posted by Avatar for user7006 @user7006

Actions