Count over 65500 pulses is posible???

lamxe

Senior Member
switch.2gif.JPG
Dear All
In this circuit can count to 100000pulses .If yes Please help me to modifier this code or give me an other best code for more learning. Thank you in advance for you time

Code:
init:
      let b0 = 0
 
main:
      if pin3 = 1 then add       ; i/o pin 3 = physical ic pin 4
      if pin3 = 0 then low 1
      endif
      goto main
 
add:
      pause 100
      let b0 = b0 + 1
      if b0 < 5 then main
      high 1                           ; i/o pin 1 = physical pin 6
      goto main
 

lbenson

Senior Member
Your first problem is that b0 is a byte variable, and 255 is the highest value it can hold.

With a word variable, for example, w10, you can count up to 65,535. If you want to count higher than that, there are a couple of ways you can do it.

You could use 2 word variables, say w10 and w11, and have your count maximum be 50,000 for each. Instead of this:

let b0 = b0 + 1
if b0 < 5 then main

You could have this:
Code:
if w10 < 50000 then
  inc w10
else
  if w11 < 50000 then
    inc wll
  else
  ' now what--you've reached or exceeded 100000
  endif
endif
if w10 < 5 then main
 

hippy

Ex-Staff (retired)
As Ibenson notes, you can use multiple variables to count up to almost any number. How to do that, how to use/combine the variables, depends on how you want to use the number.

Having one word variable count 0 to 999 and another variable to count thousands allows a number up to 65,535,999.

I would personally stick with variables counting a power of 10 value ( 10, 100, 1000, 10000 ) as that makes numbers easy to display.

Code:
Do
  w0 = w0 + 3333     ; Increment can be anything from 0 to 64536
  If w0 >= 1000 Then
    w1 = w0 /  1000 + w1
    w0 = w0 // 1000
  End If
  BinToAscii w1, b11,b12,b13,b14,b15
  BinToAscii w0, b21,b22,b23,b24,b25
  SerTxd( "Count = " , b11,b12 , "," , b13,b14,b15, "," , b23,b24,b25 , CR , LF )
Loop
 

lamxe

Senior Member
Dear Ibenson and Hippy/
Many thank you for your time help me and great code
lamxe
 
Last edited:
Top