<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Binary counter for large numbers in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Binary-counter-for-large-numbers/m-p/1407218#M23472</link>
    <description>&lt;P&gt;Hi Johnnn,&lt;/P&gt;&lt;P&gt;I appreciate your reply but, sorry, can't see any text.&lt;/P&gt;&lt;P&gt;Can you write me again?&lt;/P&gt;&lt;P&gt;With best regards&lt;/P&gt;&lt;P&gt;Mei&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 31 Jan 2022 17:28:42 GMT</pubDate>
    <dc:creator>Mei</dc:creator>
    <dc:date>2022-01-31T17:28:42Z</dc:date>
    <item>
      <title>Binary counter for large numbers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Binary-counter-for-large-numbers/m-p/1389104#M23456</link>
      <description>&lt;P&gt;Binary counter for large numbers&lt;/P&gt;&lt;P&gt;For high frequencies, i.e. short times, the controllers spoil us with timers.&lt;BR /&gt;But Software is necessary for very long periods of time. So, I developed a small counting loop with a few program lines with my S08 BDM board. A few RAM bytes are required as a counter. The simple algorithm is independent of the controller and programming language.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mei_0-1639943189373.png" style="width: 730px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/165595i2BA4B7DF63736C56/image-dimensions/730x241?v=v2" width="730" height="241" role="button" title="Mei_0-1639943189373.png" alt="Mei_0-1639943189373.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Algorithms for the 3-byte counter cycle &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(Waiting loop for a single run)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Binary counter means that all bits of the bytes used are counted with increasing significance.&lt;/LI&gt;&lt;LI&gt;Counter for large numbers means: The maximum count number increases with 2n&amp;nbsp; of n bits. Three bytes of 8 bits each, can also count up to 224 = 16.777.216, Four Bytes can count to 4.294.967.296 and so on.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Time counters need a clock. For this I used a TPM channel xxxxx with a toggle output. This enabled me to measure the clock on port PTA0.&lt;/P&gt;&lt;P&gt;Here is the algorithm for the TPM-ISR controlled step-by-step operation of the counting loop:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mei_1-1639943414390.png" style="width: 649px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/165596i09E9E72991588BA1/image-dimensions/649x271?v=v2" width="649" height="271" role="button" title="Mei_1-1639943414390.png" alt="Mei_1-1639943414390.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Algorithms for step-by-step operation&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The assembler program:&lt;/P&gt;&lt;P&gt;; --&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;3 Byte with TPM&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;--&lt;BR /&gt;; TPMCH0V, Bus cycle without divider&lt;/P&gt;&lt;P&gt;XDEF Entry,main,T_ISR&lt;BR /&gt;&lt;BR /&gt;Include 'derivative.inc'&lt;/P&gt;&lt;P&gt;Z1 EQU $67 ; Define 3 byte RAM places&lt;BR /&gt;Z2 EQU $68&lt;BR /&gt;Z3 EQU $69&lt;/P&gt;&lt;P&gt;Init_Timer:&lt;BR /&gt;mov #$4D,TPMC0VH ; H,L Comparison values for 10 ms&lt;BR /&gt;mov #$E6,TPMC0VL ;&lt;BR /&gt;mov #$54,TPMC0SC ; Channel 0 settings for toggle output on compare&lt;BR /&gt;bset 3, TPMSC ; Switch on timer start by bus&lt;BR /&gt;rts&lt;BR /&gt;; ---------------------------------------------------------------------&lt;BR /&gt;Load:&lt;BR /&gt;mov #$0F, Z1&lt;BR /&gt;mov #$27, Z2&lt;BR /&gt;mov #$00, Z3&lt;BR /&gt;rts&lt;BR /&gt;; ---------------------------------------------------------------------&lt;BR /&gt;main:&lt;BR /&gt;Entry:&lt;BR /&gt;Main_Init:&lt;BR /&gt;bsr Init_Timer ; Initialize Timer&lt;BR /&gt;bsr Load ; Load 3 byte counter values&lt;BR /&gt;lda #$12&lt;BR /&gt;sta SOPT1 ; disable watchdog&lt;BR /&gt;cli ; Allow interrupts to happen&lt;BR /&gt;lda #$FF&lt;BR /&gt;sta PTBDD ; Port B Pins are output and low&lt;BR /&gt;; ----------------------------------------------------------------------&lt;BR /&gt;loop:&lt;BR /&gt;bra loop&lt;BR /&gt;; ---------------------------------------------------------------------&lt;BR /&gt;T_ISR:&lt;BR /&gt;bclr 7, TPMC0SC ; Clear overflow flag&lt;BR /&gt;bset 7, TPMCNTH ; setting of any bit clears the counter&lt;BR /&gt;; -----------------------------------------------------------------------------&lt;BR /&gt;; Counting the Interupts with 3 bytes,&lt;BR /&gt;; ----------------------------------------------------------------------------&lt;BR /&gt;tst Z1 ; see figure with the algorithm&lt;BR /&gt;E: beq Z&lt;BR /&gt;Ee: dec Z1&lt;BR /&gt;rti&lt;BR /&gt;Z: tst Z2&lt;BR /&gt;beq Ha&lt;BR /&gt;Zz: dec Z2&lt;BR /&gt;bra Ee&lt;BR /&gt;Ha: tst Z3&lt;BR /&gt;beq La&lt;BR /&gt;dec Z3&lt;BR /&gt;M01: bra Zz&lt;BR /&gt;La: bsr Load&lt;BR /&gt;; --------------------------------------------------------------------&lt;BR /&gt;; Switch PTB6&lt;BR /&gt;; ---------------------------------------------------------------------&lt;BR /&gt;brset 6,2,L1&lt;BR /&gt;bset 6,2&lt;BR /&gt;rti&lt;BR /&gt;L1: bclr 6,2&lt;BR /&gt;rti&lt;BR /&gt;nop&lt;BR /&gt;END&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mei_0-1639944365920.png" style="width: 456px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/165598iA08271E5C52BCE88/image-dimensions/456x502?v=v2" width="456" height="502" role="button" title="Mei_0-1639944365920.png" alt="Mei_0-1639944365920.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I hope my thoughts are understandable and maybe of use to someone&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Gerd Meinert&lt;/P&gt;</description>
      <pubDate>Sun, 19 Dec 2021 20:15:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Binary-counter-for-large-numbers/m-p/1389104#M23456</guid>
      <dc:creator>Mei</dc:creator>
      <dc:date>2021-12-19T20:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Binary counter for large numbers</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Binary-counter-for-large-numbers/m-p/1407218#M23472</link>
      <description>&lt;P&gt;Hi Johnnn,&lt;/P&gt;&lt;P&gt;I appreciate your reply but, sorry, can't see any text.&lt;/P&gt;&lt;P&gt;Can you write me again?&lt;/P&gt;&lt;P&gt;With best regards&lt;/P&gt;&lt;P&gt;Mei&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jan 2022 17:28:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Binary-counter-for-large-numbers/m-p/1407218#M23472</guid>
      <dc:creator>Mei</dc:creator>
      <dc:date>2022-01-31T17:28:42Z</dc:date>
    </item>
  </channel>
</rss>

