Problem with INT timer and delay

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
ITISVARESE
Posts: 56
Joined: Sat Jul 07, 2007 3:00 pm
Has thanked: 9 times
Been thanked: 3 times
Contact:

Problem with INT timer and delay

Post by ITISVARESE »

Because i have a problem with servo component i start to write a my servo program in flowcode V4
and i think I discover that INT Timer1 and INT Timer2 don't work...
Also delay component is bugged: if You place it and checked microsecond it stay checked with next selection....
See file attached simple change INT Timer 1 in INT Timer2 and INT Timer0 (this one work).
Attachments
MioServo.fcf
(5 KiB) Downloaded 316 times

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: Problem with INT timer and delay

Post by Benj »

Hello

The servo component consumes the capture compare interrupts and the timer 1 peripheral. It is also not recommended to allow other interrupts to run as you will start to cause problems with the servo timing. Maybe you could use a very simple device to do the servo control and then pass this values over RS232 etc to control the servos. This way you could use any interrupts you wish in your main application device.

ITISVARESE
Posts: 56
Joined: Sat Jul 07, 2007 3:00 pm
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: Problem with INT timer and delay

Post by ITISVARESE »

Thank for reply,
but You don't understud me: in previous file attached there is not servo component !
I write a simple flowchart and int TMR2 and TMR1 don' work (only TMR0 work ) and there is also a problem
( look previous post) with delay components !
Problem with int timer there is also in V3

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: Problem with INT timer and delay

Post by Benj »

Hello,

I think I see the problem.

In the main loop you are setting the variable servo0 with 1500 in a loop.

Then in the interrupt routine you are subtracting 10 from the variable.

This means that the variable will probably never get below 1480 before being reset back to 1500.

Maybe you could try changing the 20ms delay in your main program to say 20s this would give the program a much higher chance of success.

ITISVARESE
Posts: 56
Joined: Sat Jul 07, 2007 3:00 pm
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: Problem with INT timer and delay

Post by ITISVARESE »

Thanks for reply,
but this is not the problem !
Program that i send is only a "nonsense program" (I attached similar that work with int timer0).
Problem is that INT TIMER1 and INT TIMER2 IS NEVER CALL !!
This explain because, for me, all component that use int timer1 and int timer2 don't work (prob. ex. Servo).
If You wan't change Enable TMR0 in Enable TMR1 or Enable TMR2 (change if You want also frequency) and You
see (also in slow flowcode simulation) that this is true; in real circuit (also in slow flowcode simulation) if i use TMR0 all OK if i use TMR1 or TMR2
circuit not work!!.
Also all example of INt in flowcode V4 use TMR0 and not other INT.
And there is also the problem with selection of microsecond in delay component!
Attachments
MioServo.fcf
(5 KiB) Downloaded 281 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
Contact:

Re: Problem with INT timer and delay

Post by medelec35 »

I have checked out the timer interrupts, and have found the following:

1) Timer0
works both in flowcode simulation and on real hardware. This Timer will call int much faster than the other two timers, so if using a low speed oscillator, you can see it works OK.

2) Timer1. Does not work in flowcode simulation (bug), but will work on real hardware. Are you using a 3.2MHz Crystal, or using RC osc? Only if you are using 3.2MHz crystal and Timer1 is set at 1:1, it will take 82ms to subtract 10. It will take a total of 12.5 seconds to get form 1500 to 0 If you are using a low speed RC osc, then it will seem like it will take a life time to get from 1500 to 0.

3) Timer2. Does not work in flowcode simulation (bug) or does not work on real hardware (bug). This is because Flowcode is not setting bit 2 of T2CON (ADDRESS 0x12)

I have modified your program so Timer2 works OK on real hardware, assuming you have a fast oscillator, and configuration of chip is set correctly.

Re time delay. Matrix are aware of that bug. If you have selected ms but want to change to microseconds, then just delete delay and place a new delay icon, select microseconds. Although it looks like ms and microseconds are both selected,when you click ok, delay will just be microseconds.
Attachments
MioServo.fcf
(5 KiB) Downloaded 298 times
Martin

ITISVARESE
Posts: 56
Joined: Sat Jul 07, 2007 3:00 pm
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: Problem with INT timer and delay

Post by ITISVARESE »

Thanks Medelec35,
Your support is best then Matrix :lol: !
I agree with You but I don't understud because Matrix don't have see this and other problem before
V4 out ...
If You have time can You see if also for You Servo don't work on real circuit (see my other post); have You
also tested I2C with eeprom 24XX on real circuit?

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

Re: Problem with INT timer and delay

Post by medelec35 »

Thanks, but I don’t agree with my support being better. Matrix support is second to none, and their knowledge is far superior to mine. They can answer questions on C and PIC related questions, I would not have a clue about.
I was just backing up what you said, because I was a bit bored on Sunday and Matrix being a business are not working on Sunday. I am just a hobbyist, support at Matrix are professionals.
Martin

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: Problem with INT timer and delay

Post by Benj »

Hello

Many thanks for the bug spot. This timer2 interrupt problem will be fixed in V4.1 of Flowcode. In the mean time you can permanantly fix the timer 2 bug by opening the FCD file for the target you are using in a text editor. Scroll to the bottom of the file and change the following lines.

Code: Select all

Opt1_1Val="intcon.PEIE=1;\nt2con.T2CKPS0=0;\nt2con.T2CKPS1=0;\nt1con.TMR2ON=1;\n"
Opt1_2="1:4"
Opt1_2Val="intcon.PEIE=1;\nt2con.T2CKPS0=1;\nt2con.T2CKPS1=0;\nt1con.TMR2ON=1;\n"
Opt1_3="1:16"
Opt1_3Val="intcon.PEIE=1;\nt2con.T2CKPS0=0;\nt2con.T2CKPS1=1;\nt1con.TMR2ON=1;\n"
Should become.

Code: Select all

Opt1_1Val="intcon.PEIE=1;\nt2con.T2CKPS0=0;\nt2con.T2CKPS1=0;\nt2con.TMR2ON=1;\n"
Opt1_2="1:4"
Opt1_2Val="intcon.PEIE=1;\nt2con.T2CKPS0=1;\nt2con.T2CKPS1=0;\nt2con.TMR2ON=1;\n"
Opt1_3="1:16"
Opt1_3Val="intcon.PEIE=1;\nt2con.T2CKPS0=0;\nt2con.T2CKPS1=1;\nt2con.TMR2ON=1;\n"
We know about the simulation issues with timer interrupts and we hope to make this better as the software progresses.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Problem with delay

Post by jadiflow »

May I resurrect this horse (partly): I have an issue with the duration of the delay in V4.
I had some weird timing issues and just did some pin set/reset with delay of 90uS and 1mS. Sampling the pin with a simple logic analyzer at 12MHz sampling rate, the actual periods at the pin (C7 on a 16F690, selected osc is INTOSC, no clk-out) are as follows:

delay macro call: delay_us(90) - actual delay: 464uS
delay macro call: delay_ms(1) - actual delay: 4.95mS

Seems they are almost a factor of 5 off.
I am also using an LCD display on this processor and that appears to work correctly. If I check the timing between successive rising edges of the 'E' signal when writing characters with minimal porcessing in between (only pick up arguments) it varies between about 1.55mS and about 1.98mS; don't know if that is as it should be but might be a clue.

Is this a known issue, and/or could anyone confirm this?

thanks,

Jan Didden

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: Problem with INT timer and delay

Post by Benj »

Hello Jan

If you are using the internal oscillator then what speed are you running it at and are you matching this speed in the Flowcode Project options window?

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

Re: Problem with INT timer and delay

Post by medelec35 »

This may not be answer, but I have had timing issues with auto watchdog selected. Is yours selected?
Martin

Post Reply