timer1

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

Moderators: Benj, Mods

Post Reply
khaled yasin
Posts: 43
Joined: Sat Sep 13, 2008 10:36 pm
Contact:

timer1

Post by khaled yasin »

why :?: :?: :?: :?: :?: :?: do i need load the flowcode variables into the timer like this
FCV_TMR1H = tmr1h;
FCV_TMR1L = tmr1l;
and then to read the timer variables into flowcode use the following.
FCV_TMR1H = tmr1h;
FCV_TMR1L = tmr1l;

and where exactly to insert each one in my program :?: :?:

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: timer1

Post by Benj »

Hello

Flowcode variables are given the prefix FCV_ in C code. It is this C code that is compiled to give you your working program.

Flowcode V3 does not currently have direct access to registers onboard the chip without using C code.

You would insert writes from your variables into the timer registers whenever you need to initialise the timer with a preset variable.

You would insert reads to your variables whenever you need to know the current timer count value.

Hope this helps.

alain31
Posts: 10
Joined: Sun Feb 24, 2008 6:32 pm
Location: Toulouse FRANCE
Contact:

Re: timer1

Post by alain31 »

Hello Benj,
Still working on my robot, I found a new problem.
Here we are, my project runs on a PIC 16F877a, I am using PWM component to run motors 1 and 2 separatly.
I intend to measure distance of each wheel using odometers. I wanted to use interrupts, one wheel distance counted by timer 0, the other one counted by timer 1. Timer 0 works fine, at the moment I've got a led flashing every 256 pulses. Timer 1 is not counting anything. I tried to load 0xFF on tmr1h to count only 256, however, not count, and moreover, when I include Timer 1, I've got wheel running reverse. I am puzzled.
Could you help ? Would Timer 1 be used also for PWM1 or PWM2

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: timer1

Post by Benj »

Hello

The PWM uses Timer2 on the 16F877A so Timer 1 should not be affected.

Does timer1 work if timer0 is not running? have you tried it running by itself. Also make sure that the clock source for timer 1 is set to use the internal clock.

Also are you running the timers on the hardware or are you simulating.

How is the PWM changing for the motor to be going in the opposite direction?

alain31
Posts: 10
Joined: Sun Feb 24, 2008 6:32 pm
Location: Toulouse FRANCE
Contact:

Re: timer1

Post by alain31 »

I agree with you that Timer2 should not be affected by use of Timer1, that's something very disturbing.
I did not try to run Timer1 without Timer0, I'll give it a try this evening.
About clok sources, I'm not simulating, my program is running on my mobile plateform, with 2 motors and IR odometers. Odo signals are connected to T0CKL/RA4 pin 6 and T1CKL/RC0 pin 15.
The motor changes sens when PWM duty ratio is reversed. 0 to 50% = REV, 50 to 100% = FW. 0% = 0, 100% = 255. The two motors are loaded at 180 at starting. Souds like CCP2 is modified when I use Timer1.
I'll see what happens whithout Timer0 and I'll tell you.

alain31
Posts: 10
Joined: Sun Feb 24, 2008 6:32 pm
Location: Toulouse FRANCE
Contact:

Re: timer1

Post by alain31 »

Hello Benj,
I tried several tests tonight.
First , I removed Interrupt on Timer0, keeping the interrupt of Timer1 on external clock RC0. No change, motor left affected, reversed.
Second, I put back the 2 interrups, on both timers, but both on internal clock at 2441 Hz, motor left affected.
3rd test, Timer0 only, still internal clock at 2441Hz, both motors forward, flashing led OK.
Going this way, I went back to simulation, at least I can see what's happening on the pwm outputs.
Program with interrupt on Timer0 only, internal clock, pwm1 = pwm2 = 62%
Program with interrupt on Timer1 only, internal clock, pwm1 = pwm2 = 62%, except every 2 seconds or so (display), pwm going 31% on both pwm.

Still puzzled. Have you got any idea ?
I attached the 2 test programs corresponding to the upon simulations, if you could have a look.
Thanks
GreenBot2_I2C_16F877A_Timer1.fcf
My program with interrupt Timer1 internal clk
(20.33 KiB) Downloaded 401 times
GreenBot2_I2C_16F877A_Timer0.fcf
My program with interrupt Timer0 internal clk
(20.33 KiB) Downloaded 320 times

alain31
Posts: 10
Joined: Sun Feb 24, 2008 6:32 pm
Location: Toulouse FRANCE
Contact:

Re: timer1

Post by alain31 »

Hello Matrix team,
Have you got any idea about the problem between Timer1 and Timer2 ?

I confirm that the problem appears during simulation and when using control board.

I don't know what to do.

:?:

Post Reply