Count input doesn't work

captnemo

New Member
This is my first forum experience. I've done some projects using a picaxe before but I've never used the "count" command
and I'm having problems. I'm using a 20M2 to count pulses from a Geiger counter. The program works fine, except the "Count" command isn't putting the count into
the variable w5.
I have C.2 connected to a pulse generater (max output 5vdc.). I know for sure the C.2 input is working, and that the pulse generator is
delivering pulses to C.2 (checked with a scope). I've got the generator set to delivery a square wave at 20 hertz with a 2ms pulse width. I've followed the example in the manual with no results.
When I do a debug, I keep getting the message "debug waiting for data."

Also. The 20M2 is suppose to run at a maximum of 32mhz, yet I've got it running at 64mhz. Is this what is reffered to as over-clocking?

The attached program is a test routine and not the actual Geiger counter program. never the less, I can't even get the "Count" command to work in a simple program.
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

The COUNT command should be working unless the voltage of the pulse is too low to be recognised. Note though that running at higher speeds does reduce the period during which counting is done. If too short it may not see any pulses.

Your program code is not attached but if you can attach that, or include it in your post wrapped in [code] ... [/code], tags I am sure someone will check it for you.
 

Goeytex

Senior Member
Hi and welcome to the forum.


The 20M2 is suppose to run at a maximum of 32mhz, yet I've got it running at 64mhz. Is this what is reffered to as over-clocking?
That's not possible. The related PIC for the 20M2 has an internal 8Mhz clock with a 4x PLL so 32Mhz is the max possible clock speed. Are you sure it is not a 20X2? . What is the marking on the chip? How did you determine that it was operating at 64MHz ?

Your attachment is missing and I suspect we will need that to get to the root of the problem.
 

captnemo

New Member
picaxe label

View attachment raytest.basThe picaxe is labeled "PICAXE 20M2.
I'm sending numerical data out to an LCD using 8 data lines. When the 20M2 is set for 64mhz. the numerical data update takes 2 seconds (looking at the display)
When running at 32 mhz it takes about 4 seconds to update. I thought it was kind of strange being able to do a "setfreq 64" without being told that the 20M2 can't
accept this frequency.

The pulse generator's return is tied to the picaxe 0v.
I'm reading a 5vdc, square wave, at pin c.2 of the picaxe on my scope.
 
Last edited:

captnemo

New Member
Well, I guess that explains the 64 mhz business. I changed the master program to M32 and it's humming now. The increment in the display is updating super fast.
So, all this time the 20m2 was actually running at 4mhz.

I'm still faced with the "count" command not working in the test program
count C.2,5000,w5
debug w5
 

Technical

Technical Support
Staff member
20 hz = a pulse every 50ms
5000 @ 32Mhz = 625ms count duration

625/50 = 12

Therefore you will never get > 50 as required in your raytest program.
 

Goeytex

Senior Member
Try the code below as a test.

Code:
[color=Green]'Counter Test

'#Picaxe 20M2[/color]
[color=Navy]#no_data
#terminal 38400[/color]

[color=Black]init:[/color]
[color=Blue]setfreq M32             [/color][color=Green]'set cpu frequency to 32mhz.[/color]
[color=Blue]let [/color][color=Purple]dirsB [/color][color=DarkCyan]= [/color][color=Navy]%11111111   [/color][color=Green]'set pins b.0-b.7 as outputs[/color]
[color=Blue]let [/color][color=Purple]dirsC [/color][color=DarkCyan]= [/color][color=Navy]%10111011   [/color][color=Green]'Set pin C.2 as an input.[/color]

[color=Blue]symbol Pulse_Pin [/color][color=DarkCyan]= [/color][color=Blue]C.2
symbol [/color][color=Purple]Pulse_Count [/color][color=DarkCyan]= [/color][color=Purple]W5[/color]
[color=Blue]symbol time1 [/color][color=DarkCyan]= [/color][color=Navy]5000     [/color][color=Green]' 625 ms[/color]
[color=Blue]symbol time2 [/color][color=DarkCyan]= [/color][color=Navy]40000    [/color][color=Green]' 5 seconds[/color]

[color=Black]Main:[/color]

[color=Blue]do
      count Pulse_Pin[/color][color=Black],[/color][color=Blue]time1[/color][color=Black],[/color][color=Purple]Pulse_Count    [/color][color=Green]'Count for 625ms @ 32MHz 
      [/color][color=Blue]sertxd ([/color][color=Red]"Counted "[/color][color=Black],#[/color][color=Purple]Pulse_Count[/color][color=Black],[/color][color=Red]" Pulses in 625ms"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
      
      count Pulse_Pin[/color][color=Black],[/color][color=Blue]time2[/color][color=Black],[/color][color=Purple]Pulse_Count    [/color][color=Green]'Count for 5 seconds
      [/color][color=Blue]sertxd ([/color][color=Red]"Counted "[/color][color=Black],#[/color][color=Purple]Pulse_Count[/color][color=Black],[/color][color=Red]" Pulses in 5 seconds"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)
      
      sertxd (CR[/color][color=Black],[/color][color=Blue]LF)
      
      if [/color][color=Purple]pulse_count [/color][color=DarkCyan]> [/color][color=Navy]50 [/color][color=Blue]then
           high C.0           
           pause [/color][color=Navy]1600        [/color][color=Green]'On for 1600/8 ms = 200 ms blip
           [/color][color=Blue]low C.0
      end if
                   
loop[/color]
 
Top