Page 1 of 1

How to read timer 1 into a varable for flowcode4

Posted: Tue Jul 21, 2009 11:59 am
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

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

Posted: Tue Jul 21, 2009 12:59 pm
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;

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

Posted: Tue Jul 21, 2009 6:45 pm
by DanDMan
Thank you.