• 4Jun2016 UpCounterV1.js
    The previous Upcounter.js has been extended.
    The Pins table has entries for Timer 8 channels added.
    The setupCounter() function has dropped the prescale argument as it is not active.
    A new function has been added. UpCounter.prototype.setupCounter32=function(Mtim,Mchan,Mfilter,Stim);
    It allows two timers to be chained together to form a 32 bit counter.
    The master timer (Mtim) is used to input an external signal on Mchan (1 or 2) and be filtered by Mfilter. When the Mtim overflows the slave timer (Stim) count is incremented. Mtim acts as a 16 bit prescaler to Stim
    The count value (CNT) from Mtim is the LSB and the CNT value from STM is the MSB part of the count.

    There are 4 internal paths used to chain the timers named ITR0, ITR1, ITR2, and ITR3.
    The array TSvalues is used by the function getTS() to determine the chaining path.
    This is all discussed on page 397 of the RM0008 Reference manual
    15.3.15 Timer synchronization
    Tables 82 and 86
    See attached file TSvalues.xlxs
    RM0008 Reference manual
    http://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf
    AN2592
    http://www.st.com/content/ccc/resource/technical/document/application_note/0c/88/73/b9/d9/7f/4d/70/CD00165509.pdf/files/CD00165509.pdf/jcr:content/translations/en.CD00165509.pdf
    AN4013
    http://www.st.com/content/ccc/resource/technical/document/application_note/54/0f/67/eb/47/34/45/40/DM00042534.pdf/files/DM00042534.pdf/jcr:content/translations/en.DM00042534.pdf
    I’m still puzzling about the nature of these inter timer links. Obviously the master timer is the source of the signals. Can a link with one master timer talk to more than one slave timer?
    It is conceivable to connect a master to slave 1 and then have slave 1 act as a master to slave 2. This would make a 48 bit counter possible.

    The Mfilter argument is discussed on pages 342 and 406. Value can range from 0 thru 15 with 0 being no filtering. It inserts a delay that acts as a de-bounce of a noisy signal.
    In sections 14.4.3 TIM1&TIM8 slave mode control register (TIMx_SMCR) and 15.4.3 TIMx slave mode control register (TIMx_SMCR)

    The counters so far are based on pages 377 and 378 of the RM0008 Reference manual
    External clock source mode 1.

    Pages 379 and 380 discuss External clock source mode 2. The problem is associating the ETR to a pin on the Espruino board. This will entail setting up mode 2 and trying all the pins until the one that works for each timer. Using the ETR as an external input allows the timer to operate in gated mode. A second timer can be used to generate a one time pulse to gate the first timer for a more precise measurement of frequency.

    Place UpcounterV1.js in the modules folder of a WebIDE project and the remaining js files in the project folder.
    The reader can test these functions by modifying the timer numbers and channel numbers in the test programs. I encourage readers to try the variations and report any problems. An external connection between the timer3 PWM output on pin B0 and the input pin of the counter is required.


    5 Attachments

About