Do task according to pulse count or frequency

Sanchit

New Member
Hi

I am trying to make a program for a picaxe 20m2 chip such that it
continuously counts pulses in 100 milli seconds and do specific
tasks according to the no. of pulses, for ex- light an LED
connected on pin b.0 for 1 second when the pulse count is 100
and light another LED which is connected to pin b.1 when the
pulse count is 200. it should be like that it ''continuously
monitors'' the pulses coming on one of the pins (say c.7) and do
tasks accordingly but I have no idea how to do it.

Actually, i want my picaxe to respond to audio signals which
contains only one single frequency (like 1000 Hz at one time)
coming from a source (say a mobile phone's audio jack) and do
what i have programmed it to do when it gets a particular
frequency (1000Hz ---> light an LED on pin b.0).

WHAT I HAVE DID TILL NOW :-

I played a 1000 Hz tone from my phone, converted it to 5 volt
digital pulses(sort of) using an op amp as they were analog audio
signals (which i think can't be counted by picaxe) when they came
out from my phone's audio jack, made my picaxe count those
pulses using this program-

main:
count c.7, 100, w1 ; count pulses in 100 milli secs (at
4MHz)
debug ; display value
goto main ; loop back to start

And success! (means my crappy digital pulse convertor(sort of)
worked! ) It worked perfectly and it showed the value '100' in w1
in the debug window. After it, I tried 2000 Hz and it showed the
value '200' indebug window.

Now i want to write a program so that it do different things on
different frequencies but i don't have any idea about the code.

Help please :p
 

westaust55

Moderator
Welcome to the PICAXE forum.

Your basic test case can form the core using the COUNT command. At the default M2 clock speed of 4 MHz this command can accept frequencies up to 25 kHz.

Have a look at the SELECT command which could be used to take the resulting number, 100, 200, 300, etc from each frequency and perform a series of commands corresponding to the value obtained from each frequency.

Do not forget that depending upon the timing to re-enter the COUNT command after handling a previous sample and action, you may see an occasional difference in the value received by the COUNT command. So adding some tolerance may be useful.
So code along these lines my be the sort of thing you are trying to achieve.

Code:
main:
    DO
        COUNT c.7, 100, w1 ; count pulses in 100 milli secs (at 4MHz)
        SELECT w1
            CASE 98 TO 102
                HIGH B.0
                PAUSE 1000
                LOW B.0
            CASE 198 TO 202
                HIGH B.1
                PAUSE 1000
                LOW B.1
            ELSE
                ; do something else
            ENDSELECT
        LOOP  ; loop forever
 

Buzby

Senior Member
Hi Sanchit,

Welcome to the forum !.

You've done great getting the phone signal into the PICAXE.

The next part is easy.

Your code puts a value in w1, and you want to do different things depending on the value.

Have a look at the IF and SELECT commands.
 

Sanchit

New Member
Welcome to the PICAXE forum.

Your basic test case can form the core using the COUNT command. At the default M2 clock speed of 4 MHz this command can accept frequencies up to 25 kHz.

Have a look at the SELECT command which could be used to take the resulting number, 100, 200, 300, etc from each frequency and perform a series of commands corresponding to the value obtained from each frequency.

Do not forget that depending upon the timing to re-enter the COUNT command after handling a previous sample and action, you may see an occasional difference in the value received by the COUNT command. So adding some tolerance may be useful.
So code along these lines my be the sort of thing you are trying to achieve.

Code:
main:
    DO
        COUNT c.7, 100, w1 ; count pulses in 100 milli secs (at 4MHz)
        SELECT w1
            CASE 98 TO 102
                HIGH B.0
                PAUSE 1000
                LOW B.0
            CASE 198 TO 202
                HIGH B.1
                PAUSE 1000
                LOW B.1
            ELSE
                ; do something else
            ENDSELECT
        LOOP  ; loop forever

Thank you so much man! i got it working exactly as i wanted it to!
 
Top