Page 1 of 1

Timer1

Posted: Thu Aug 16, 2007 9:45 pm
by KeesD
How can I use TMR1 of a PIC16F627A in flowcode?

Posted: Fri Aug 17, 2007 8:45 am
by Steve
You have 2 choices:

1) Use a "custom" interrupt, and configure it by hand.

2) Modify the 627A FCD file.

The second option is perhaps the easiest to explain because we already support the TMR1 module in some FCD files - e.g. the 16F877a.

Open the 16F627A FCD file and alter the following:

Code: Select all

[Interrupts]
;first 3 should always be 1=TMR0, 2=RB0INT, 3=PORTB
;any other interrupts need to also have this set: "intcon.PEIE=1;\n"
GeneralInit="intcon.GIE=1;\n"
Count=3
1=TMR0
2=RB0INT
3=PORTB
This should be changed to:

Code: Select all

[Interrupts]
;first 3 should always be 1=TMR0, 2=RB0INT, 3=PORTB
;any other interrupts need to also have this set: "intcon.PEIE=1;\n"
GeneralInit="intcon.GIE=1;\n"
Count=4
1=TMR0
2=RB0INT
3=PORTB
4=TMR1
And then add the following section at the end of the FCD file:

Code: Select all

[TMR1]
;NOTE: this osc is enabled and turned on as part of the Opt1 code
Name="TMR1 Overflow"
FlagReg=pir1
FlagBit=TMR1IF
EnReg=pie1
EnBit=TMR1IE
OptCnt=2
TmrOpt=2
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Transition on T1CKI pin"
Opt1_1Val="intcon.PEIE=1;\nt1con.T1OSCEN=1;\nt1con.TMR1ON=1;\nt1con.TMR1CS=1;\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="intcon.PEIE=1;\nt1con.T1OSCEN=1;\nt1con.TMR1ON=1;\nt1con.TMR1CS=0;\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t1con = t1con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t1con = (t1con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t1con = (t1con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t1con = (t1con & 0x0F) | 0x30;\n"

Posted: Fri Jan 04, 2008 3:08 am
by Ondra
Hi I am using the PIC16F690 and want to use timer1. Can the above work for me? Also do you have a list of the PIC's where Flowcode already has support for timer1 built in.

Ondra

Posted: Fri Jan 04, 2008 10:17 am
by Steve
A similar approach should work for that chip. You will need to check that the same registers and bits are used in this chip.

I think the only chip currently to have the TMR1 code is the 16F877a.

Posted: Fri Jan 04, 2008 2:00 pm
by Ondra
Thanks Steve.
I don't want to make a mess of this. Could you give me just a little more detail. In particular which line of code would I be looking to change changing?

Ondra

Posted: Fri Jan 04, 2008 3:53 pm
by Benj
Hello Ondra

Browse down to the [Interrupts] section of the FCD, change the line Count=3 to Count=4 and then add the following line to the end of the section.

Code: Select all

4=TMR1
Then add the following section of code to the end of the FCD file

Code: Select all

[TMR1]
;NOTE: this osc is enabled and turned on as part of the Opt1 code
Name="TMR1 Overflow"
FlagReg=pir1
FlagBit=TMR1IF
EnReg=pie1
EnBit=TMR1IE
OptCnt=2
TmrOpt=2
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Transition on T1CKI pin"
Opt1_1Val="intcon.PEIE=1;\nt1con.T1OSCEN=1;\nt1con.TMR1ON=1;\nt1con.TMR1CS=1;\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="intcon.PEIE=1;\nt1con.T1OSCEN=1;\nt1con.TMR1ON=1;\nt1con.TMR1CS=0;\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t1con = t1con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t1con = (t1con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t1con = (t1con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t1con = (t1con & 0x0F) | 0x30;\n"


If you are worried about making mistakes then make a backup of the FCD file first so that you can always replace it if your edited file goes wrong.

Let me know how you get on.

Posted: Fri Jan 04, 2008 4:17 pm
by Ondra
Thanks Steve. I'll give it try.

Re: Timer1 not working

Posted: Tue Feb 05, 2008 4:35 pm
by Ondra
Ok. I tried this and can't get it working. I changed the fcd file and created a small program
that blinks an Led. I chose the a prescaler of 1:8 which gave me a frequence of 2400Hz.
I set a variable to increment and a light to blink ever second through an "If" block. when I
use the TMR0 at 1:256 (75Hz) it works. when I change to TMR1 nothing happens. I chose
both clock options with no luck. What am I missing? Thanks.

Ondra

Re: Timer1

Posted: Tue Feb 05, 2008 4:57 pm
by Benj
Hello Ondra

Try replacing the [TMR1] section with the following code.

I think that the problem was that the low power oscillator was being enabled for timer 1.

Code: Select all

[TMR1]
;NOTE: this osc is enabled and turned on as part of the Opt1 code
Name="TMR1 Overflow"
FlagReg=pir1
FlagBit=TMR1IF
EnReg=pie1
EnBit=TMR1IE
OptCnt=2
TmrOpt=2
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Transition on T1CKI pin"
Opt1_1Val="intcon.PEIE=1;\nt1con.T1OSCEN=0;\nt1con.TMR1ON=1;\nt1con.TMR1CS=1;\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="intcon.PEIE=1;\nt1con.T1OSCEN=0;\nt1con.TMR1ON=1;\nt1con.TMR1CS=0;\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t1con = t1con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t1con = (t1con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t1con = (t1con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t1con = (t1con & 0x0F) | 0x30;\n"
Also make sure that you are assigning the internal clock to the Timer1 interrupt. Also worth noting that Timer 1 is a 16-bit timer and as such will take precisely 256 times longer to timeout then timer 0. This could be the problem. The Flowcode timeout value may be set up for an 8 bit timer. In this case simply devide the output frequency stated in Flowcode by 256 to get the actual frequency. If you wish to use the timer1 interrupt as an 8 bit timer then you can always run the following C command at the start of the interrupt.

Code: Select all

tmr1h = 255;
Hope this helps. :P

Re: Timer1

Posted: Tue Feb 05, 2008 5:19 pm
by Ondra
IT WORKSSSSSS!
Thanks Ben

Re: Timer1

Posted: Tue Feb 05, 2008 6:39 pm
by Benj
Hey thats great, Thanks for letting me know.

Did you have to use the C code to clear the tmr1h register?

Re: Timer1

Posted: Wed Feb 06, 2008 1:50 pm
by Ondra
No I didn't. Thanks

Ondra

Re: Timer1

Posted: Fri Mar 07, 2008 11:37 am
by Ondra
Compiler error. Benj or Steve I think this might tie in to what was done in this situation. When I try to use the RB Port change I get this error.
The timer 1 is working fine.
Ondra


C:\E-Tank\flowcode\ElinK\BBRS232.c(397:9): error: unknown identifier 'RBIE'
C:\E-Tank\flowcode\ElinK\BBRS232.c(397:9): error: unexpected '.' operator
C:\E-Tank\flowcode\ElinK\BBRS232.c(397:2): error: failed to generate expression
C:\E-Tank\flowcode\ElinK\BBRS232.c(397:2): error: invalid operand 'intcon.RBIE'
C:\E-Tank\flowcode\ElinK\BBRS232.c(397:13): error: failed to generate expression
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:21): error: unknown identifier 'RBIF'
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:21): error: invalid operand 'RBIF'
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:18): error: failed to generate expression
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:18): error: invalid operand '<<'
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:13): error: failed to generate expression
C:\E-Tank\flowcode\ElinK\BBRS232.c(405:13): internal error: failed to generate 'if' expression
BBRS232.c success

failure

.........
Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED

Re: Timer1

Posted: Fri Mar 07, 2008 11:55 am
by Benj
Hello Ondra

Which chip are you using. Also is it a custom interrupt you are using or one of the pre-set interrupts.

Re: Timer1

Posted: Fri Mar 07, 2008 9:16 pm
by Ondra
I'm using the PIC 16F690. Its a pre-set interrupt.

Ondra

Re: Timer1

Posted: Mon Mar 10, 2008 5:29 pm
by Ondra
Any opinions on this one?

Ondra

Re: Timer1

Posted: Tue Mar 11, 2008 9:57 am
by Ondra
I really need some help on this guys.

Re: Timer1

Posted: Tue Mar 11, 2008 10:15 am
by Ondra
I also notice that in the Interrupt list there is an RB0 But the data sheet for the 16F690 does not have an RB0
pin. Please help with this.

Ondra

Re: Timer1

Posted: Tue Mar 11, 2008 10:55 am
by Steve
Hi Ondra,

Sorry for the delay in answering this for you.

Yes, there is a problem with the FCD file for the 16F690 (in fact, the whole family: 631/677/685/687/689/690).

To rectify it, you should change the entries "RBIE" and "RBIF" in the [PORTB] section of the FCD file to "RABIE" and "RABIF".

To answer your other question, the "INT" pin on the 16F690 is on RA2.

Re: Timer1

Posted: Tue Mar 11, 2008 11:30 am
by Ondra
Thanks I'll give it a try.

Ondra

Re: Timer1

Posted: Tue Mar 11, 2008 12:32 pm
by Ondra
Ok I think there are other issues with the FCD. The error's gone but the interrupt's still not working, are there other issues with the 16F690 file.
From the beginning the timer1 and timer0 were working. After I had the problem caused by the RB Port change interrupt the timer1 and timer0
stopped working. My question is, when I compiled the program could it be possible that it is corrupted, caused by earlier issue of the RB Port change issue?
And could that be causing the timers not to operate?

Ondra

Re: Timer1

Posted: Tue Mar 11, 2008 12:55 pm
by Steve
I can't see how your program could become corrupted. Flowcode generates fresh C code each time it compiles, so there should be no corruption.

I suggest you create a simple program to test the timer interrupts.

Re: Timer1

Posted: Mon Mar 17, 2008 2:01 pm
by Benj
Here are the latest versions of the FCD files with the PortB interrupt moved to PortA.