Page 1 of 1

Pulse counter

Posted: Wed Nov 04, 2009 2:18 pm
by alexander70
Hi! I'm trying to make a pulse counter using the timer external input (pin T0CKI). But somehow the counter does not respond to button A4 (pin T0CK1) and count the internal frequency. Where I made a mistake?

Re: Pulse counter

Posted: Wed Nov 04, 2009 4:17 pm
by Benj
Hello Alexander

I think the attached program should work for you. The problem is that the pin toggles are first counted in the timer register which is only accessible via C code. When the actual timer interrupt is called we have actually had 256 specific clock edges on the input pin. I have rejigged your program so it also should show the pulses as the timer register is incremented.

Let me know how you get on when using it on your hardware.

Re: Pulse counter

Posted: Thu Nov 05, 2009 6:40 am
by alexander70
Hi! In the simulator Flowcode program count internal impulses, you have not noticed this? I was not able to compile a HEX file:
It seemed an error message. (below) I usually check the program in the program Proteus VSM ( http://www.labcenter.co.uk ) but that requires HEX file




File name: F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c
Generated by: Flowcode v4.1.1.55
Date: Thursday, November 05, 2009 09:09:10
Licence: Demo

***DEMO VERSION***


NOT FOR COMMERCIAL USE

http://www.matrixmultimedia.com


Launching the compiler...
E:\Program Files\Matrix Multimedia\Flowcode V4\BoostC\boostc.pic16.flowcode.exe -v -t PIC16F887 "counter_fl3.c"
BoostC Optimizing C Compiler Version 6.95 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2009 Pavel Baranov
Copyright(C) 2004-2009 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


counter_fl3.c
Starting preprocessor: E:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\pp.exe "F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c" -i E:\PROGRA~1\MATRIX~1\FLOWCO~2\BoostC\include -d _PIC16F887 -la -c2 -o "F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.pp" -v -d _BOOSTC -d _PIC16


.........................................................

F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(492:14): error: unknown identifier 'tmr0l'
F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(492:14): error: invalid operand 'tmr0l'
F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(492:12): error: failed to generate expression
F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(544:2): error: unknown identifier 'tmr0l'
F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(544:2): error: invalid operand 'tmr0l'
F:\Microcintrollers\FlowCode Examples\Flowcode 3 Examples from programm\Counter\counter_fl3.c(544:8): error: failed to generate expression
counter_fl3.c success

failure

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

Re: Pulse counter

Posted: Thu Nov 05, 2009 9:25 am
by Benj
Hello Alexander

Unfortunatley the program will not simulate in Flowcode correctly as it still assumes that the clock is driven from the internal clock. However the program should work well in Proteus and also on the hardware.

This version now compiles correctly.

Re: Pulse counter

Posted: Thu Nov 05, 2009 10:01 am
by alexander70
Unfortunately the program does not work in Proteus, the LCD is clean and does not react to button A4. I have attached all necessary files. Other examples in Proteus run. For comparison, I put in the archive file Better_Clock_Example1_16F887.hex which works in the Proteus.

Re: Pulse counter

Posted: Thu Nov 05, 2009 11:52 am
by Benj
Hello Alexander

Sorry it seems I missed the LCD start out of the program. If you add it to the start of the Main then the program should run correctly.

Re: Pulse counter

Posted: Thu Nov 05, 2009 12:07 pm
by alexander70
Thank you! Now the program works. Is possible in generally to make a pulse counter without interruption, just on a survey of a PIN?

Re: Pulse counter

Posted: Thu Nov 05, 2009 12:45 pm
by Benj
Hello Alexander

At the moment you could add a lot of extra code to your program and the counter would still work 100%, though the display may take longer to refresh. If you just use a non interrupt software method then you will need to constantly monitor the pin to ensure you dont miss a count. This would severley reduce the amount of extra functionality you could put into your program. It depends on how fast your input signal can be.

Eg if your using the non interrupt based version then LCD writes alone can take several milliseconds where you could be missing pulses.

Re: Pulse counter

Posted: Thu Nov 05, 2009 1:20 pm
by alexander70
Hi! I made a counter on the 7-segment LED display, but it is working not properly. Where I made a mistake?

Re: Pulse counter

Posted: Thu Nov 05, 2009 1:33 pm
by alexander70
I have found my mistake, I connected the segments of the indicator to port B and had a conflict with PIN B0:)

Re: Pulse counter

Posted: Thu Nov 05, 2009 2:05 pm
by alexander70
I did setting of the first indicator digit, but when I set the value, the remaining 2 indicator digits ceases to shine. How to make correctly digits setting?

Re: Pulse counter

Posted: Thu Nov 05, 2009 2:44 pm
by Benj
Hello alexander

Ok I think you just need another 5ms delay after the last 7seg write to allow it time to light up. Persistence of vision should do the rest of the work for you.

When you press the switch that triggers the 1 second delay the 7 segs will temorarily pause on the digit last used. You could use a timer interrupt to control the 7 segment displays. Eg have a counter that counts from 0 to 2 and then resets back to 0 eg count = (count + 1) mod 3. You can then use a switch icon in the interrupt service routine to chosse the current display segment and write the correct value to it. You would not need the 5ms delays then.

Re: Pulse counter

Posted: Fri Nov 06, 2009 5:46 am
by alexander70
Hi! Thank you for information. Do You know the suitable examples of switсh icon using or 7 segment LED control by timer?

Re: Pulse counter

Posted: Fri Nov 06, 2009 9:28 am
by Benj
Hello Alexander

Sorry I just noticed that this is the V3 forum. The switch icon is only available in v4.

Basically just increment a counter in your interrupt service routine and then depending on the count value write the data to the appropriate 7seg.

Re: Pulse counter

Posted: Wed Nov 11, 2009 1:09 pm
by alexander70
Hello!
I want to ask, possible to make pulse counter in FlowCode 3 using normal pin for count, not using interrupt?

Re: Pulse counter

Posted: Wed Nov 11, 2009 1:48 pm
by Benj
If you just use a non interrupt software method then you will need to constantly monitor the pin to ensure you dont miss a count. This would severley reduce the amount of extra functionality you could put into your program. Overall It depends on how fast your input signal is going to be.

Re: Pulse counter

Posted: Wed Nov 11, 2009 2:05 pm
by alexander70
Thank you, I tried, but maybe I made a mistake somewhere. Where I gone wrong? I have attached project.

Re: Pulse counter

Posted: Thu Nov 12, 2009 4:39 pm
by alexander70
I made this algorithm, it works, now can count pulses on any input:)