Plusing an electrical mechanical counter

Posted on
  • Hello,
    I have an electrical mechanical counter that I'd like to control with Espruino.­et/196.html

    The counter takes a 5V pulse to count up, which sounds simple but apparently, it is 5V AC, not DC.
    Does anyone know how I can pulse 5V AC for 50ms?

    Thank you

  • After some more playing around I think I misunderstood the AC part.
    I don't think it requires AC but rather 'alternating' pulses. When wiring up the counter directly to pins A0 & A1 the following code works.
    Can you see any issues with this? It seems to work Ok, but I'm worrying I'm still misunderstanding something.

    var  on = false;
    setInterval(function() {
      on = !on;
      digitalWrite(A0, !on);
      digitalWrite(A1, on);
    }, 50);
  • Also is it safe to wire this device directly to my Espruino?

  • It might be that it just needs a pulse? so digitalPulse(A0,1,100) for a 100ms pulse on A0.

    It's possible that if you leave it powered all the time that's not good for it?

    That page says the impedance is 550 ohms, so 3.3*1000/550 = 6mA when driven from the Espruino's 3.3v - so from that side of things you're ok.

    However if it's inductive it might be trying to put some extra voltage into Espruino when turned on/off and it might be an idea to put some 'clamp' diodes across it. I don't suppose you have an oscilloscope you could check with?

  • I have a cheap DIY oscilloscope. Would that do the job?­61916872.html

    This is a bit beyond me. If you can tell me how to set it up and what to look for I'll give it a go.

  • Sorry for the delay - wow, that scope looks like a bargain!

    Well, I'd attach the scope across the mechanical counter, set up the trigger on it at 1.5v (50% of the signal) and then try running your code. Basically you're looking for reasonably straight edges on the signal as it goes from high-low and low-high. If you see the signal 'overshooting' and going up much above 3.3v (the normal voltage for the IO) or below 0v then you know that the inductance in the counter is pushing voltage in to the microcontroller, which is bad for it long-term. Otherwise you're fine

  • Thanks for replying. It's a very basic scope but works great for simple tasks like this.
    Here are the results, I'm no expert but I don't see any spike so I guess we're Ok?
    If you can see any issues please let me know.

    2V DC 0.1ms

    1V DC 0.1ms

    50ms view of pluses

    Video of pluses

  • @Owen,

    in the page linked in your first post, the tech spec talks about DC impedance (20℃): 550Ω±50Ω. If you have a multimeter (or decently precise resistors for a voltage divider), you can measure your device's DC impedance... and that will tell how much current the device will draw.

    The minimum pulse with (and maximum frequency) on given voltage is there to guarantee proper counting / mechanical movement. If you would open the device, you would see a simple relay setup which for every close (pulse) ratchets a gear for a tooth / given angle, similar to the rotary switches used in old, pulse driven dialing / connecting systems in phone offices (see­witch).

    For the referenced device of 550Ω±50Ω on 5V, it is 10mA... and 6mA on 3.3V, which is really low... (explainable by the 200:1 reduction gear for incrementing LSD by 1). Based on your forum history, I assume your Espruino device is an Espruino Pico... and a Pico can drive and sink easily 10mA. Since it has 5V compatible GPIO pins, you may run it in sink mode / open drain / open collector mode to drive it with 5V to achieve higher pulse frequency. Be aware that for sink mode the logic is reverse: pin high is idle, pin low for pulse time is for pulse.

    After you have it setup, turn the coil on ('infinit' / long pulse), and measure the voltage across the coil. Should you not have sufficient voltage, you can use more than one pin in parallel for driving / sinking. I did something similar in Powering / control power of sensors / peripherals by Espruino pins. I could not use the (usually preferred) sink mode because I needed a shared ground.

    Btw, I have the same DSO and I like it a lot. I 3d-printed (and painted) a case with legs for it. The legs swing out to have the DSO in an angle comfortable for reading.... (For higher frequencies I have an old, still CRT and non-S oscilloscope).

    PS: You can change the title of the conversation to reflect better what this is all about.

  • Sorry for the delay - as @allObjects says, I think this is absolutely fine.

    Thanks for the pics - as you say there are no huge peaks on the waveform so I wouldn't be concerned about this at all

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

Plusing an electrical mechanical counter

Posted by Avatar for Owen @Owen