How does watch work ?

Posted on
  • Still working on my rotary phone.
    For recognizing a simple test should help, thats the idea.

    function initWP(){
      var arr = new Uint8Array(100),pnt = 0,pulsePort = D3;
      pulsePort.mode('input_pullup');
      function pulseHnd(e){arr[pnt++] = e.state;}
      function logPulse(){
        console.log(new Uint8Array(arr.buffer,0,pnt));
        clearWatch();
      }
      setWatch(pulseHnd,pulsePort,{repeat:true­,edge:1,debounce:5});
      setWatch(pulseHnd,pulsePort,{repeat:true­,edge:-1,debounce:5});
      setTimeout(logPulse,5000);
    }
    

    Next switched to terminal window and checked several times.

    initWP()
    =undefined
    new Uint8Array([1, 1, 0])
    >initWP()
    =undefined
    new Uint8Array([1, 1, 1, 1, 1, 0])
    >initWP()
    =undefined
    new Uint8Array([1, 1, 1, 1, 0])
    >initWP()
    =undefined
    new Uint8Array([1, 1, 1, 0])
    >initWP()
    =undefined
    new Uint8Array([0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0])
    > 
    

    How can I get raising edge several times, without having falling edge between ?
    Checked the same with one watch (edge:0) and got similiar result.

  • Can you just try a single setWatch(pulseHnd,pulsePort,{repeat:true­,edge:0,debounce:5}); and see if that behaves any differently?

    What you're doing with the two calls is setting up two debounce instances, one for rising and one for falling. While you'd expect them to work the same way, it's possible that there's some problem there.

  • Using edge:0 was my first step. Thats were the problem started.
    I changed to 2 watches to have the option to use different debounce for falling and for raising.
    Anyway, I switched back to one watch for testing.

    function initWP(){
      var arr = new Uint8Array(100),pnt = 0,pulsePort = D3;
      pulsePort.mode('input_pullup');
      function pulseHnd(e){arr[pnt++] = e.state;}
      function logPulse(){
        console.log(new Uint8Array(arr.buffer,0,pnt));
        clearWatch();
      }
      setWatch(pulseHnd,pulsePort,{repeat:true­,edge:0,debounce:5});
      setTimeout(logPulse,5000);
    }
    

    Problem stays.
    Next, based on a hint from @MaBe, used 2 wires connecting on a breadboard to simulate pulses instead of my rotary and got similiar problem. This time I've falling edges without raising between (2nd and 3rd example)

    initWP()
    =undefined
    new Uint8Array([0, 1, 0, 1, 0, 1, 0, 1, 0, 1])
    >initWP()
    =undefined
    new Uint8Array([0, 0, 1, 0, 1, 0, 1, 0, 1])
    >initWP()
    =undefined
    new Uint8Array([0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0])
    
  • What about using a different pin to verify.

    connect D3 with D4 and send some pulse:

    setTimeout(initWP,1E3);
    setTimeout(()=>{
          digitalPulse(D4,0,[100,100,100,100,100,1­00,100,100]);
    },2E3);
    
    

    Output should look like this:

    new Uint8Array([0, 1, 0, 1, 0, 1, 0, 1, 0])
    
  • Just checking, what device is this on? MDBT42?

    I can reproduce it here too - a simple setWatch(print,...) is enough. It definitely seems broken somehow - I've filed an issue at https://github.com/espruino/Espruino/iss­ues/1902

    Without debounce you'd expect that you would get multiple events though, just because sometimes the noise is so fast that my the time the IRQ handler fires the pin has already changed state.

    But that obviously shouldn't cause issues with the debounce.

    You should be able to work around it pretty easily if you need to just be doing some debouncing yourself though - because I imagine you're only really interested in the falling edge.

  • Ok, I basically have a fix for this, but it's not tested properly yet and I'll be on holiday next week so I'm not going to push this to master :)

    I've just pushed a branch called setWatch_fix_1902 - and you should be able to try builds on https://www.espruino.com/binaries/travis­/setWatch_fix_1902/

  • Simple testing looks good.
    Testing with latest version of rotary (W48) works fine.

    Testing with very old rotary gives problems.
    I've to dig deeper there with oscilloscope and/or logic analyzer

  • @JumJum,

    you may need to take into account the timings of the dialing life cycle.

    From your first line of the first post I assume that you have an 'old' rotary phone and you want to detect which digits and number it dialed (to drive a touch tone sequence?).

    Remembering how rotary phones worked: when letting the disk go, the loaded spring pulls/rotates the disk it back in rest position with a constant angle speed. Angle speed is controlled - kept 'constant' / preventing from accelerating and running away - by a governor, either centrifugal friction or air resistance governor like they were used in old steam machines and still are used in spring driven music boxes. A combination of a single shot watch and timeouts as as key controls of a timing state machine may make it work:

    1. Initialize pulse counter and timeout handles to 0, and setup the single shot watch.
    2. On firing of single shot:
      • Clear 2nd timeout if it is set and clear the handle ( if (h1) h1 = clearTimeout(h1); )
      • Increment pulse counter.
      • Set 1st timeout to about 60%..80% of the time between pulse begins for re-setup of the single shot watch.
      • Set 2nd timeout to about 120%..140% of the time between pulse begins for detecting the end of pulse sequence.

    This is just the core... some startup and end processing (clear watch and handles). There is most likely another switch that will tell when a dial is about to happen. A watch on that could be used to start the state machine.

    Robust debouncing is a tough thing to do...

    Versuchst du sowas anzuschliessen? Gelb-Gruen: Puls, Weiss-Braun: Ruheposition (?)


    5 Attachments

    • Waehlscheibe.png
    • PTT_TF3_50_1979_front_full.png
    • PTT_TF3_50_1979_schema.png
    • PTT_TF3_50_1979_internals.png
    • D_Post_FeWAp611-1.png
  • Thanks for checking! I'd be interested to hear from anyone else willing to try the setWatch branch: https://www.espruino.com/binaries/travis­/setWatch_fix_1902/

    Always handy to have another set of eyes to see if setWatch got broken somehow before I merge these changes ;)

  • @allObjects,
    thanks for your feedback. I've a 612-2 and an older phone made from copper.
    There is one switch for the hook.
    Another sensor is for dialing.
    Last not least one sensor for pulses.
    612-2 works fine, all signals are recognized with simple debouncing.
    The copper phone works for hook and dialing, but pulses give strange results. Debouncing by Espruino does not help. From test to test, I get totally different results. Looks like hardware of the phone does not like reproducable results. Sometimes even no pulse is detected.
    Anyway, I will first try to get my 612-2 running with a SIM800.
    And later on come back to the copper phone.


  • @JumJum,

    thank for the pictures... smart simple very space resourceful solution for the governor that controls the speed of the dial: reverse worm gear instead of small and large cog wheel.

    Do you notice irregularity in the rotation of the cam?

    Did you think of cleaning the contacts? And check the wire and (clean) other contacts in the circuit? I assume you already wend down that lane... Worst cace, get a micro switch or optical gate and catch the signal totally independent of the phone wiring.

    'Related' question: what do you do for hand set (microphone and ear piece)?

    Looking forward to your solution. I have some phone hardware laying around for a while now. When the project was hot and I had ordered as A6C Quad Band on a breakout board, I got instead sent just the module... and by the time the other options arrived, the need was not pressing anymore, so the stuff still 'waits' for some time to squash - squander? - The A6C then arrived w/ a camera w/ flash, and the SIM800L is with PCB antenna.


    1 Attachment

    • espPhoineHW.jpg
  • @allObjects,
    my reason to choose SIM800 was size (and price)
    Adding a micro switch, good point, before giving up, I'll take that.
    Micro and speaker, hmm, no idea yet.
    As soon as all steps before are working, I'll see what I can do with that.

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

How does watch work ?

Posted by Avatar for JumJum @JumJum

Actions