How to read timer 1 into a varable for flowcode4

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm
Contact:

How to read timer 1 into a varable for flowcode4

Post by DanDMan »

I am programming a pic 16HV616 device to sample analog voltage and then adjust output signal timing(in seconds). I need to read the timers 0, 1, and 2. I am using flowcode 4 and don't know how to set an manually read(get the timer value into a variable) the timers.

I do not plan on using interrupts. The sequence goes something like this:

Code: Select all

Start
sample A/D 1 and calculate delay time 1
sample A/D 2 and calculate delay time 2
Clear and start timer 1
do other functions
read timer 1
is timer 1 > calculated delay time 1 (if yes then switch output and check for delay time 2)
          (if not go to do other functions)
Sample A/D 1
is sample 1 < or > last sample value (if yes, calculate new time switch output if new timer < current timer time)
          (if not go to do other functions)
SO my question is how do I set up timer 1, and read the value into a variable? I am using flowcode 4.

Thanks, Dan

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: How to read timer 1 into a varable for flowcode4

Post by Benj »

Hello

Firstly lookup the timer name in the device datasheet. For timer0 the timer registers are called tmr0l and tmr0h. Using the standard 8-bit timer0 only the low byte is needed.

Create a flowcode variable eg Timer0
Using a C code icon read the contents of the register into your flowcode variable.

Code: Select all

FCV_TIMER0 = tmr0l;
For 16-bit timers such as timer1 you will have to create a 16-bit variable in Flowcode eg Timer1.
Then using a C code icon you can read the two registers into your INT variable. Note that Flowcode INT variables are signed so a timer value of 32767 will give you a negative number if you are using a print number function etc.

Code: Select all

FCV_TIMER1 = tmr1l;
FCV_TIMER1 = FCV_TIMER1 | (tmr1h << 8);
You could get around this by only reading the high byte into a byte variable eg.

Code: Select all

FCV_TIMER1 = tmr1h;

DanDMan
Posts: 11
Joined: Wed Jul 15, 2009 8:28 pm
Contact:

Re: How to read timer 1 into a varable for flowcode4

Post by DanDMan »

Thank you.

Post Reply