Timer1

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

Moderators: Benj, Mods

KeesD
Posts: 6
Joined: Thu Aug 16, 2007 9:40 pm
Location: Leiden (NL)
Has thanked: 2 times
Been thanked: 1 time
Contact:

Timer1

Postby KeesD » Thu Aug 16, 2007 9:45 pm

How can I use TMR1 of a PIC16F627A in flowcode?

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Postby Steve » Fri Aug 17, 2007 8:45 am

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"

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Postby Ondra » Fri Jan 04, 2008 3:08 am

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

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Postby Steve » Fri Jan 04, 2008 10:17 am

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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Postby Ondra » Fri Jan 04, 2008 2:00 pm

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

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Postby Benj » Fri Jan 04, 2008 3:53 pm

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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Postby Ondra » Fri Jan 04, 2008 4:17 pm

Thanks Steve. I'll give it try.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1 not working

Postby Ondra » Tue Feb 05, 2008 4:35 pm

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

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Timer1

Postby Benj » Tue Feb 05, 2008 4:57 pm

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Tue Feb 05, 2008 5:19 pm

IT WORKSSSSSS!
Thanks Ben

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Timer1

Postby Benj » Tue Feb 05, 2008 6:39 pm

Hey thats great, Thanks for letting me know.

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Wed Feb 06, 2008 1:50 pm

No I didn't. Thanks

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Fri Mar 07, 2008 11:37 am

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

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Timer1

Postby Benj » Fri Mar 07, 2008 11:55 am

Hello Ondra

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

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Fri Mar 07, 2008 9:16 pm

I'm using the PIC 16F690. Its a pre-set interrupt.

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Mon Mar 10, 2008 5:29 pm

Any opinions on this one?

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Tue Mar 11, 2008 9:57 am

I really need some help on this guys.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Tue Mar 11, 2008 10:15 am

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

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Re: Timer1

Postby Steve » Tue Mar 11, 2008 10:55 am

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.

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Tue Mar 11, 2008 11:30 am

Thanks I'll give it a try.

Ondra

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: Timer1

Postby Ondra » Tue Mar 11, 2008 12:32 pm

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

User avatar
Steve
Matrix Staff
Posts: 3110
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 396 times
Contact:

Re: Timer1

Postby Steve » Tue Mar 11, 2008 12:55 pm

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.

User avatar
Benj
Matrix Staff
Posts: 14655
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4644 times
Been thanked: 4266 times
Contact:

Re: Timer1

Postby Benj » Mon Mar 17, 2008 2:01 pm

Here are the latest versions of the FCD files with the PortB interrupt moved to PortA.
Attachments
FCD_Generate_File.zip
(13.4 KiB) Downloaded 338 times