Jump to content



Photo
- - - - -

Pinscape Pico - ULN2803 - Optocoupler/MOSFET board and PWM


  • Please log in to reply
1 reply to this topic

#1 zag

zag

    Neophyte

  • Members
  • Pip
  • 1 posts

  • Flag: Switzerland

  • Favorite Pinball: HS

Posted Today, 03:16 PM

I m trying to control a feedback device with a PWM signal via Pico --- ULN2803 --- optocoupler/MOSFET board. PWM works if I just use the ULN 2803 with an LED (without the o/M board). With the optocoupler it's just on and off. If I replace the Pico with a KL25Z, PWM control works. The voltages on the input port of the optocoupler are about the same at 0,50,100% (Pico, KL25Z).

     outputs: [
         // DOF port #1
         {
             device: { type: "gpio", gp: 7, pwm: true },  // GPIO output on GP7
         },

 

 

update: the PWM frequency seems to be different. KL25Z: 2 kHz, Pico: 20 kHz (but I am not an expert, just used a DS212). If it is the frequency. How to change the Pinscape Pico PWM freqency to 2 kHz?


Edited by zag, Today, 04:46 PM.


#2 mjr

mjr

    Pinball Wizard

  • Members
  • PipPipPipPipPip
  • 3,332 posts

  • Flag: United States of America

  • Favorite Pinball: Medieval Madness

Posted Today, 05:55 PM

I think you're right to suspect the PWM frequency is the issue.  Optocouplers have limits on how fast a PWM rate they can accept because the phototransistors they use have fairly slow switching times. Pinscape Pico uses 20 kHz default, as you observed, which was chosen specifically with optos in mind - most of them shouldn't start having problems until you hit about 80-100 kHz.  But some of them do seem to be a lot slower than that, so you must have lucked into a particularly slow batch.  Trying a lower rate is a good plan.

 

There are two ways to set the GPIO PWM frequency, both in the JSON configuration settings 

 

First, you can set the global default for all GPIO ports, via the top-level "pwm" setting:

pwm: {
    defaultFreq: 2000
},

Second, you set the frequency on an individual port, overriding the global default, with the "freq" property in the "device" section:

outputs: [
   // DOF port 1
   {
      device: { type: "gpio", gp: 7, pwm: true, freq: 2000 },
   },
]

The JSON Config Reference has details on all of these settings.