Count Command Not Working

CDRIVE

Senior Member
I'm obviously missing something here but I would expect W1 in the following code to = 0 until it sees 8 pulses within a period of 5 seconds. I'm simulating the pulses by click toggling C.1 in the simulator. For some odd reason W1 = 32000 immediately after starting the simulator, whether or not I've toggled C.1 or not. What have I missed here?

Thanks,
Chris
Code:
main:

Count C.1, 5000, W1 ; count pulses in 5secs (at 4MHz)
If W1 > 8 Then
    High C.2
Else
;    Low C.2
End If

goto main ; loop back to start
 

hippy

Technical Support
Staff member
PE6 takes the count result from the 'word' values list in the "Values" tab of the simulation panel ( usually at bottom left ). It doesn't count actual clicks upon the pin referenced.
 

CDRIVE

Senior Member
PE6 takes the count result from the 'word' values list in the "Values" tab of the simulation panel ( usually at bottom left ). It doesn't count actual clicks upon the pin referenced.
Hippy, sorry for the delay in replying. I clicked the "Check For Updates" option in PE6 and things didn't go well. It took me this long to get up and running again.

Anyway, I'm embarrassed to say that don't understand your reply. Are you saying I can't simulate the Count Command by clicking animated pins?

Thanks,
Chris
 

hippy

Technical Support
Staff member
Are you saying I can't simulate the Count Command by clicking animated pins?
That is correct. You specify what count result you want to get rather than having to click the pins which would be difficult if there were only a short time period, tedious if you wanted a high count, impossible if you wanted both.
 

CDRIVE

Senior Member
Some time has passed and I'm working with the Count function again.
Question: Does the Count function constantly zero the count value stored in the word variable (Wn) prior to executing each count period?

Thanks,
Chris
 

hippy

Technical Support
Staff member
Yes, the value in the variable will be how many pulses were counted during the specified period.
 

CDRIVE

Senior Member
Hello Hippy. The more I play with the Count function the more questions I seem to have. Take this code snippet for example. If the pulse rate input = 1 PPS it would take 5 full seconds for the Picaxe to count and load w1 with the required value of 5 to satisfy the If statement immediately following it . So how does the Picaxe deal with it? I know or think I know that the Count function doesn't loop within itself for 5 seconds before executing the next line of code. Since you confirmed that Count zeros w1 prior to taking the next count this begs the question. If the program has looped back to the Count function prior to completing the count period does it simply skip to the next line of code until 5 seconds has elapsed? If so, would it be more accurate to say that the Count function only zeros w1 after it has completed the count period? In other words not every time the program flows back to it?

Thank you,
Chris


Code:
main:

Count C.4, 5000, w1 
        
If w1 >= 5 Then
      High C.1
Else
      Low C.1
End If
                  
Goto main
 

hippy

Technical Support
Staff member
When simulating, COUNT is instant, takes the Simulation panel word value and drops it into the variable, then continues with the next line immediately. So in this case, simulating will not have the 5 second loop time a real PICAXE would have.

The Simulation panel word value should be set to the number of counts you want to see when COUNT has counted for its specified period.

If you want the COUNT's time delay you can add a 5 second delay in only while simulating using "#IFDEF SIMULATING" ...

Code:
Count C.4, 5000, w1
#IfDef SIMULATING
   Pause 5000
#EndIf
 

CDRIVE

Senior Member
Actually all of my last post was referencing a live picaxe or simulation in VSM. Were any of my statements wrong or inaccurate?

Thank you.
Chris
 

hippy

Technical Support
Staff member
I have re-read you question and I think the answer is that the COUNT command does loop within itself for 5 seconds ( or whatever period is specified ), will not continue to the next command until that time has elapsed.
 

CDRIVE

Senior Member
Yes, that certainly clears thing up. Including some of my misconceptions. Sorry for being a bit pesky but I like to have a solid understanding of things. As always you're extremely knowledgeable, prompt and above all helpful.

Thank you very much.
Chris
 

CDRIVE

Senior Member
This is just an update for those using the Count function and simulating in Picaxe VSM. It's basically a confirmation of what Hippy sated. If you run this basic code in VSM you will see Pin C.1 cycling high and low similar to using a Pause 1000 where the two Count functions are.

Chris

Code:
; Target Picaxe: 08M2

Main:
Count C.3, 1000, W1
    High C.1
Count C.3, 1000, W1
    Low C.1
GoTo Main
 
Top