Time measurement

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Yashman
Posts: 1
Joined: Wed Mar 21, 2012 9:45 pm

Time measurement

Post by Yashman »

Hello! I'm working on a simple program that shows on the LCD display the delay between pressing two buttons in hundreths of seconds. User presses the first button and the counter starts to increase by 0.00512 by interrupt on TMR0 with 19531.250 Hz frequency and 20MHz clock speed. This interrupt also reads the second button's state and if it's pressed the interrupt is disabled. Then the delay is showed on the LCD display. This is how the program should work, but it doesn't work at all. It only displays "000" after the second button is pressed. I'm using PIC16F628. Maybe I should somehow change the Project's or Chip's options? You can see my Flowcode file in attachment. Thanks in advance.
Attachments
Time measurement.fcf
(11 KiB) Downloaded 261 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Time measurement

Post by medelec35 »

Hi Yashman,
Reason your flowchart is not working is due to the way float variables are handled.
to add floats to gether you need to use the fadd (found by clicking on functions within the calculation box.
E.g time = fadd(time,0.00512)
If fadd, fmul ect are not used then results will always be 0

You then have two more addition problems
1) Using Floats within an interrupt is not a good idea and will lead to corruption problems.

2) Using floats with 16F628, you will very likely run out of space on the chip.

If I was you I would use port interrupt for the switches, then use a count variable (use integer type) within timer2 (timer 2 makes it very east to set required interrupt time).
E.g Count = Count +1

The timer interrupt can be configured for say 0.1 of a ms.
So when 1st switched is press the Count variable is reset.
Timer is running so Count is incrementing on each timer2 interrupt.
Second switched is pressed. Count variable contains the total time in 0.1ms
E.g if final count is 1500 then total time = 0.15seconds.
here are the settings for 0.1ms = 1/0.1ms = 10KHz:
10KHz timer2.png
(47.92 KiB) Downloaded 1425 times
You will just need to convert 1500 into required format.

Note: Timer 2 will not simulate in Flowcode V4, only simulates in Flowcode V5. But will work on your hardware.

If you do decide to try what I have suggested and you get stuck, then if you post your flowchart,
I will see if I can help you get it working.

Martin
Martin

User avatar
DavidA
Matrix Staff
Posts: 1076
Joined: Fri Apr 23, 2010 2:18 pm
Location: Matrix Multimedia Ltd
Has thanked: 58 times
Been thanked: 258 times
Contact:

Re: Time measurement

Post by DavidA »

Hi guys since this is a Flowcode v4 topic ill move it to the Flowcode v4 forums,

IF you need access to the topic Yashman please follow the instructions here: http://www.matrixmultimedia.com/support ... f=29&t=602

Post Reply