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.

PIC Timer and decimals

Status
Not open for further replies.

lacr

New Member
I am using a PIC 19F690 and I am trying to setup TIMER0 for my first time.
For the record I am using MicroCode and PICKit2.

Basically what I want to do is log a time period elapsed and calculate a litre(s) of liquid used during the elapsed time.

I have a sensor that I can accuratly calculate the litres/min flow rate of water going through a pipe.

So once I determine my flow rate I then want to log the elapsed time and multiply it by the flow rate to determine to water used.

The problem I have is this;

Elapsed time = 3 Seconds
Flow Rate = 10 Litres per second
Water used = (3x10)/60 = 0.5 litres

The problem I have is I do not know how to use decimal places and I dont think the above calculation will work, will it? :confused:

This is my untested section of code (Sec is to be calculated from the interupt routine, yet to be written);

Main:
Time = Sec ' Set as Start time
IF Flow = Lmin THEN ' If the water flow rate hasnt changed_
GOSUB GETFLOW ' keep checking until it does
ENDIF
Elapsed = Sec - Time ' Capture the time period Note: Sec updated by interupt
Wused = Elapsed * Flow ' Calculate water used during elapsed time
Flow = Lmin ' Set new Flow value for next period Note: Lmin comes from GETFLOW Routine
Tused = Tused + Wused ' Add water used during period to total used so far
GOTO Main:

I also need some help to setup the interupt routine to update SEC every 1 second.

If anyone can help me with this I would greatly appreciate it...




MOD Edit: Spam link deleted
 
Last edited by a moderator:
Status
Not open for further replies.

Latest threads

Back
Top