Timer1
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
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:
This should be changed to:
And then add the following section at the end of the FCD file:
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
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
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"
- 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:
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.
Then add the following section of code to the end of the FCD file
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.
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
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Timer1 not working
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
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
- 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
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.
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.
Hope this helps.
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"
Code: Select all
tmr1h = 255;
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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
Hey thats great, Thanks for letting me know.
Did you have to use the C code to clear the tmr1h register?
Did you have to use the C code to clear the tmr1h register?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Timer1
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
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
- 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
Hello Ondra
Which chip are you using. Also is it a custom interrupt you are using or one of the pre-set interrupts.
Which chip are you using. Also is it a custom interrupt you are using or one of the pre-set interrupts.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Timer1
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
pin. Please help with this.
Ondra
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Timer1
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.
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
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
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
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: Timer1
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.
I suggest you create a simple program to test the timer interrupts.
- 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
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 447 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel