Help with COUNT Command

ROYMARNEWICK

New Member
Help with the COUNT command would be really appreciated. I am a novice!!
My program is supposed to measure the number of pulses on an input pin over a 10 second period and then calculate the frequency of the input signal. The command used is : count C.0,10000,w0 ( input pin is C.0 / time period is 10 seconds / output result to w0 ). While the program is running, I rapidly click on the Pin c.0 button on the simulation screen to simulate an input signal (on/off cycles).
When the program is run, I note the following:
* the program runs through all the program lines including the above line but does not hang about for the 10 seconds while it reads the input signals.
* the value of w0 stays as 0 on the simulation screen
Please help in understanding what is going wrong.
Thanks
 

cpedw

Senior Member
Which Picaxe are you using? 08M2's C.0 is an output only so can't work with COUNT. Most others it's an I/O so COUNT should be OK.

The simulator doesn't do absolutely everything exactly like a real chip - some commands involving timing are particularly challenging for it but you need an expert (not me) to pronounce on simulating COUNT.

Derek
 

ROYMARNEWICK

New Member
Which Picaxe are you using? 08M2's C.0 is an output only so can't work with COUNT. Most others it's an I/O so COUNT should be OK.

The simulator doesn't do absolutely everything exactly like a real chip - some commands involving timing are particularly challenging for it but you need an expert (not me) to pronounce on simulating COUNT.

Derek
Thanks for your reply. Chip is 18M2 and C.0 is an Input, so it would be great to get more guidance. Thanks again.
 

lbenson

Senior Member
In simulation, the COUNT target value takes the value given for the pin in the values pane of the simulation window. To easily test different values, put a break on the COUNT statement and alter the value for your pin, e.g., C.0.
COUNT sim.jpg
 

ROYMARNEWICK

New Member
In simulation, the COUNT target value takes the value given for the pin in the values pane of the simulation window. To easily test different values, put a break on the COUNT statement and alter the value for your pin, e.g., C.0.
View attachment 23906
thanks for your reply. I have had a quick look at your reply and am somewhat confused. I am a novice - but will look in more detail tomorrow. I may need to send you my code to see if it makes sense to you. If it does then I will assume the coding as correct !!! Thanks again.
 

lbenson

Senior Member
I may need to send you my code
Best always to post code to the forum, so many eyes can look at it. When posting code, to preserve formatting, put it between the forum tags "[ code]" and "[ /code]" (except omit the spaces).

In simulating, some values which change rapidly in real life cannot be well simulated, so for certain commands, like COUNT and READADC, values that you want to test may be set in a pane labelled "Values" in the window in the lower left of the screen. This is where the chip outline is normally shown when the "Digital" pane is selected.
 

ROYMARNEWICK

New Member
Best always to post code to the forum, so many eyes can look at it. When posting code, to preserve formatting, put it between the forum tags "[ code]" and "[ /code]" (except omit the spaces).

In simulating, some values which change rapidly in real life cannot be well simulated, so for certain commands, like COUNT and READADC, values that you want to test may be set in a pane labelled "Values" in the window in the lower left of the screen. This is where the chip outline is normally shown when the "Digital" pane is selected.
Thanks for your additional guidance - will check it out tomorrow when my mind is clearer!!
 

erco

Senior Member
What's your hardware setup for sending pulses? Are you switching from low to high or vice versa. Pullup/pulldown resistors as required (or the pullup command)? You can't just break the connection from 0 or 5V and assume the line goes to the other rail, you have to have a high-value pullup/pulldown resistor.

If your hardware is working properly, this code might work (untested). Are you running at 4 MHz default clock speed?

do
count C.0,10000,w0
sertxd (#w0, 13,10)
loop
 
Top