Pulse counter

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Pulse counter

Post 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?
Attachments
counter_fl3.fcf
(6 KiB) Downloaded 772 times
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.
Attachments
counter_fl3.fcf
(7.5 KiB) Downloaded 954 times

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post 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
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.
Attachments
counter_fl3.fcf
(7.5 KiB) Downloaded 757 times

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post 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.
Attachments
counter.zip
(25.8 KiB) Downloaded 778 times
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post 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?
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post by alexander70 »

Hi! I made a counter on the 7-segment LED display, but it is working not properly. Where I made a mistake?
Attachments
counter7segfl3new1.fcf
(8 KiB) Downloaded 570 times
Respectfully, Alexander

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post by alexander70 »

I have found my mistake, I connected the segments of the indicator to port B and had a conflict with PIN B0:)
Respectfully, Alexander

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post 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?
Attachments
counter7segfl3new3.fcf
(8.5 KiB) Downloaded 535 times
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post 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?
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post by alexander70 »

Hello!
I want to ask, possible to make pulse counter in FlowCode 3 using normal pin for count, not using interrupt?
Respectfully, Alexander

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Pulse counter

Post 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.

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post by alexander70 »

Thank you, I tried, but maybe I made a mistake somewhere. Where I gone wrong? I have attached project.
Attachments
counter7segfl3new4.fcf
(8 KiB) Downloaded 437 times
Respectfully, Alexander

alexander70
Posts: 79
Joined: Mon Aug 03, 2009 12:14 pm

Re: Pulse counter

Post by alexander70 »

I made this algorithm, it works, now can count pulses on any input:)
Attachments
counter7segfl3new10.fcf
(7 KiB) Downloaded 790 times
Respectfully, Alexander

Post Reply