Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

picbasic pro 'COUNT' command help

Status
Not open for further replies.

chyun84

New Member
i'm currently working on hand clapping projects using pic16f84a
my condition is like this:
clap once within 3 sec = one output
clap twice within 3sec = another output
clap thrice within 3sec = another output

now my problem is:
i trying to use COUNT command for counting pulse received within 3 sec, but it doesn't works for me, i'm not sure whether my code is correct or not, hope anyone can help me on this,
my code is as below:

temp VAR BYTE
main:
Count PORTA.0, 3000
IF Count = %1 Then sub1
IF Count = %2 Then sub2
End
GoTo main

sub1:
For temp = 1 TO 7
PulsOut PORTB.0, 150
Pause 13
End
GoTo main:

sub2:
For temp = 1 TO 7
PulsOut PORTB.0,150
Pause 13
Count PORTA.0, 3000
IF Count = %3 Then main
Else
sub2
EndIF
GoTo sub2
 
OK I will byte..:eek:

What is %1 and %2? Interger for 1 and 2 to compare to a byte? Remove the %, you do not need them.

You have to provide a circuit for anyone to see what is tied to port a.0

Do you know that your port b.0 circuit is working as well?
 
hmm....i try to changed and now my code is as below:
now i've no compilation error, but do u think the code works fine for my conditions? coz i don't have the ic burner now, hard for me to test now..
the code below still lack of sub3. the sub3 will be used to stop the all all the operation (looping of sub2), but i still not yet discover what command to use, mind to give some idea? thanks if can ^^

TRISA = $ff ' set porta as input
TRISB = $00 ' set portb as output
PORTB = $00

temp VAR BYTE
w1 var byte


main:
Count PORTA.0, 3000, w1
IF w1 = 1 Then sub1
IF w1 = 2 Then sub2
if w1 = 3 then sub3
End
GoTo main

sub1:
For temp = 1 TO 7
PulsOut PORTB.0, 150
Pause 13
NEXT temp
GoTo main:


sub2:
LOOP: For temp = 1 TO 7
PulsOut PORTB.0, 150
Pause 13
NEXT temp
GOTO loop:

sub3:
 
Again, what is connected to Port A.0? The code looks fine as long as you are getting the right pulses on that pin.

Also sub1 and sub2 are the same so you will not see a difference between 1 clap and 2.
 
porta.0 is connected to the output of the handclap signal.
for the sub2, what i do is:
when there's 2 claps, the servo will loop the sub1 (continuous of sub1) and kept continue moving until 3 claps is obtained for stopping the servo..
 
chyun84 said:
porta.0 is connected to the output of the handclap signal.
for the sub2, what i do is:
when there's 2 claps, the servo will loop the sub1 (continuous of sub1) and kept continue moving until 3 claps is obtained for stopping the servo..

The way you have the code you will never leave sub2. Also, that End there,
if you do nothing for 3 seconds the program will end?
 
what i want is, if the condition is in sub2 and its continuous position, then the program will never end if i didnt do anything in 3 seconds unless it receives 3 claps. while sub2 is in progress, then the program will wait for the detection of 3 claps...that's waht i want. i just learn this picbasic yesterday and i didnt know much the programming, so i need ur advise... hehe. so what should i change??
 
Do you have a functional spec on this? Can you write out what you want? I assume your pulse IN is working (and you do not publish the circuit).

I can re-read the first post (again), or you can tell me where it is broke. I pointed out if you do nothing for 3 seconds the program will stop..

In sub2 do you need to to do a Count at that end? I am lost.
 
ops.. sorry for that...
ok.. what i want is:
my circuit is sound dectection circuit, there will be output when i claps my hands... the output of clapping signal will be connected to the input of pic16f84 which is porta.0 or other port. so my projects will be like this:

when i clap once, the program will run the servo in specific time or angles such as 270deg (i'm using continuous servo)

when i clap twice, the program will run the servo continuously without stop unless it receive 3 claps which stop all the program...

i use COUNT command because i want the program counts how many pulses it receive in specific times such as 3sec, then only provide the output...

so do u think it is possible to use this command or any other suggestion??
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top