Wrong 18F25K22 FCD Timer Definition
Moderator: Benj
Wrong 18F25K22 FCD Timer Definition
Hello,
the timer 1/3/5 of the PIC18F25K22 are absolute identical 16bit timers.
But why is the definition of the timers settings in the FCD- file different?
For example:
[TMR1]
....
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"
[TMR3]
....
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t3con = t3con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t3con = (t3con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t3con = (t3con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t3con = (t3con & 0x0F) | 0x30;\n"
[TMR5]
...
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t5con = t5con & 0xE7;\n"
Opt2_2="1:2"
Opt2_2Val="t5con = (t5con & 0xE7) | 0x08;\n" <--
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xE7) | 0x10;\n" <---
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xE7) | 0x18;\n" <-----
Finally, the TMR5 definition is absolute wrong and you mask the wrong bits for the prescaler definition.
Thanks
the timer 1/3/5 of the PIC18F25K22 are absolute identical 16bit timers.
But why is the definition of the timers settings in the FCD- file different?
For example:
[TMR1]
....
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"
[TMR3]
....
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t3con = t3con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t3con = (t3con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t3con = (t3con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t3con = (t3con & 0x0F) | 0x30;\n"
[TMR5]
...
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t5con = t5con & 0xE7;\n"
Opt2_2="1:2"
Opt2_2Val="t5con = (t5con & 0xE7) | 0x08;\n" <--
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xE7) | 0x10;\n" <---
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xE7) | 0x18;\n" <-----
Finally, the TMR5 definition is absolute wrong and you mask the wrong bits for the prescaler definition.
Thanks
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Wrong 18F25K22 FCD Timer Definition
Hi,
Thanks for the findings. You are absolutely right..
Ben please update that in master file..
Enamul
Thanks for the findings. You are absolutely right..
The above code should be following..[TMR5]
...
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t5con = t5con & 0xE7;\n"
Opt2_2="1:2"
Opt2_2Val="t5con = (t5con & 0xE7) | 0x08;\n" <--
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xE7) | 0x10;\n" <---
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xE7) | 0x18;\n" <-----
Code: Select all
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t5con = t5con & 0x0F;\n"
Opt2_2="1:2"
Opt2_2Val="t5con = (t5con & 0x0F) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0x0F) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0x0F) | 0x30;\n"
Enamul
- Attachments
-
- 18f25k22.jpg (93.38 KiB) Viewed 8546 times
Re: Wrong 18F25K22 FCD Timer Definition
Hello,
here a little bit more changes on the file:
here a little bit more changes on the file:
I hope you can use it for the master file[TMR1]
Name="TMR1"
HandlerCode="#ifndef MX_INTHANDLER_pir1_TMR1IF\n#define MX_INTHANDLER_pir1_TMR1IF\nif (ts_bit(pir1, TMR1IF) && ts_bit(pie1, TMR1IE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\n\tFCM_%n();\n\tcr_bit(pir1, TMR1IF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"
EnableCode="st_bit(pie1, TMR1IE);\n"
DisableCode="cr_bit(pie1, TMR1IE);\n"
OptCnt=2
PrescaleOpt=2
MaxTimerOverflow=65536
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Internal clock (Fosc)/ falsche Sim."
Opt1_1Val="st_bit(intcon, PEIE);\nst_bit(t1con, TMR1ON);\nst_bit(t1con, TMR1CS0);\nsr_bit(t1con, TMR1CS1);\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon, PEIE);\nst_bit(t1con, TMR1ON);\ncr_bit(t1con, TMR1CS0);\nsr_bit(t1con, TMR1CS1);\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t1con = t1con & 0xCF;\n"
Opt2_2="1:2"
Opt2_2Val="t1con = (t1con & 0xCF) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t1con = (t1con & 0xCF) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t1con = (t1con & 0xCF) | 0x30;\n"
Opt3="16-Bit Read/Write Mode"
Opt3Cnt=2
Opt3_1="Timer1 in one 16-bit operation"
Opt3_1Val="st_bit(t1con, T1RD16);\n"
Opt3_2="Timer3 in two 8-bit operation"
Opt3_2Val="cr_bit(t1con, T1RD16);\n"
[TMR3]
Name="TMR3"
HandlerCode="#ifndef MX_INTHANDLER_pir2_TMR3IF\n#define MX_INTHANDLER_pir2_TMR3IF\nif (ts_bit(pir2, TMR3IF) && ts_bit(pie2, TMR3IE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\n\tFCM_%n();\n\tcr_bit(pir2, TMR3IF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"
EnableCode="st_bit(pie2, TMR3IE);\n"
DisableCode="cr_bit(pie2, TMR3IE);\n"
OptCnt=2
PrescaleOpt=2
MaxTimerOverflow=65536
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Internal clock (Fosc)/ falsche Sim."
Opt1_1Val="st_bit(intcon, PEIE);\nst_bit(t3con, TMR3ON);\nst_bit(t3con, TMR3CS0);\ncr_bit(t3con, TMR3CS1);\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon, PEIE);\nst_bit(t3con, TMR3ON);\ncr_bit(t3con, TMR3CS0);\ncr_bit(t3con, TMR3CS1);\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t3con = t3con & 0xCF;\n"
Opt2_2="1:2"
Opt2_2Val="t3con = (t3con & 0xCF) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t3con = (t3con & 0xCF) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t3con = (t3con & 0xCF) | 0x30;\n"
Opt3="16-Bit Read/Write Mode"
Opt3Cnt=2
Opt3_1="Timer3 in one 16-bit operation"
Opt3_1Val="st_bit(t3con, T3RD16);\n"
Opt3_2="Timer3 in two 8-bit operation"
Opt3_2Val="cr_bit(t3con, T3RD16);\n"
[TMR5]
Name="TMR5"
HandlerCode="#ifndef MX_INTHANDLER_pir5_TMR5IF\n#define MX_INTHANDLER_pir5_TMR5IF\nif (ts_bit(pir5, TMR5IF) && ts_bit(pie5, TMR5IE))\n{\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 1;\n\t#endif\n\tFCM_%n();\n\tcr_bit(pir5, TMR5IF);\n\t#ifdef USE_FLOWCODE_ICD\n\t\textern char ICD_Interrupt_Enable = 0;\n\t#endif\t\n}\n#else\n#warning "This interrupt has previously been enabled, so the macro <%n> may never get called."\n#endif\n"
EnableCode="st_bit(pie5, TMR5IE);\n"
DisableCode="cr_bit(pie5, TMR5IE);\n"
OptCnt=3
PrescaleOpt=2
MaxTimerOverflow=65536
Opt1="Clock Source Select"
Opt1Cnt=2
Opt1_1="Internal clock (Fosc) / falsche Sim."
Opt1_1Val="st_bit(intcon, PEIE);\nst_bit(t5con, TMR5ON);\nst_bit(t5con, TMR5CS0);\ncr_bit(t5con, TMR5CS1);\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon, PEIE);\nst_bit(t5con, TMR5ON);\ncr_bit(t5con, TMR5CS0);\ncr_bit(t5con, TMR5CS1);\n"
Opt2="Prescaler Rate"
Opt2Cnt=4
Opt2_1="1:1"
Opt2_1Val="t5con = t5con & 0xCF;\n"
Opt2_2="1:2"
Opt2_2Val="t5con = (t5con & 0xCF) | 0x10;\n"
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xCF) | 0x20;\n"
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xCF) | 0x30;\n"
Opt3="16-Bit Read/Write Mode"
Opt3Cnt=2
Opt3_1="Timer5 in one 16-bit operation"
Opt3_1Val="st_bit(t5con, T5RD16);\n"
Opt3_2="Timer5 in two 8-bit operation"
Opt3_2Val="cr_bit(t5con, T5RD16);\n"
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Wrong 18F25K22 FCD Timer Definition
Hi,
Have you noticed one problem if you add 16/8-bit option? It will be fine for 16-bit as pre-scalar but for 8-bit int frequency will be shown wrong..
Because of the following code..
Above is true for 16-bit...
but for 8-bit following should be..
Enamul
Have you noticed one problem if you add 16/8-bit option? It will be fine for 16-bit as pre-scalar but for 8-bit int frequency will be shown wrong..
Because of the following code..
Code: Select all
MaxTimerOverflow=65536
but for 8-bit following should be..
Code: Select all
MaxTimerOverflow=256
Re: Wrong 18F25K22 FCD Timer Definition
Good morning,
I don't think so, the Timer 1/3/5 of this PIC is only a 16bit Timer and the rollover of the timer is always 65536. So the simulation works fine and I can't find some problems during the operation of the PIC.
I support this option because:
Your remark with the wrong shown frequency is correct if we change the Timer0 from 8bit to 16bit.
The next feature you can implement in Flowcode.
Kind regards,
I don't think so, the Timer 1/3/5 of this PIC is only a 16bit Timer and the rollover of the timer is always 65536. So the simulation works fine and I can't find some problems during the operation of the PIC.
I support this option because:
I think it is better than the 8bit solution and the failure rate is lower than the 8bit instruction.
When a read from the TMRxL register is requested, the
value of the TMRxH register is simultaneously loaded
into the TMRxH buffer register. When a read from the
TMRxH register is requested, the value is provided
from the TMRxH buffer register instead. This provides
the user with the ability to accurately read all 16 bits of
the Timer1/3/5 value from a single instance in time.
In contrast, when not in 16-Bit mode, the user must
read each register separately and determine if the
values have become invalid due to a rollover that may
have occurred between the read operations.
Your remark with the wrong shown frequency is correct if we change the Timer0 from 8bit to 16bit.
The next feature you can implement in Flowcode.
Kind regards,
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
Re: Wrong 18F25K22 FCD Timer Definition
Hi,
Yes! you are right. The above is true for TMR0 not for TMR1/3/5
Enamul
Yes! you are right. The above is true for TMR0 not for TMR1/3/5
Enamul
- 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: Wrong 18F25K22 FCD Timer Definition
Hello,
Thanks for the bug spot. The problem was caused because earlier 18F devices used timer 5 in this alternate way and it looks like the code was simply copied over from the earlier devices.
I have updated all odd numbered timers for the later PICs now so they should all work correctly and also allow for the 8/16 bit operation as well as the external clocking option.
Let me know if you spot any further issues.
Edit- Just spotted a bug in the timer 5 FCD code, damn, regenerating again
Thanks for the bug spot. The problem was caused because earlier 18F devices used timer 5 in this alternate way and it looks like the code was simply copied over from the earlier devices.
I have updated all odd numbered timers for the later PICs now so they should all work correctly and also allow for the 8/16 bit operation as well as the external clocking option.
Let me know if you spot any further issues.
Edit- Just spotted a bug in the timer 5 FCD code, damn, regenerating again
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
- Enamul
- Posts: 1772
- Joined: Mon Mar 05, 2012 11:34 pm
- Location: Nottingham, UK
- Has thanked: 271 times
- Been thanked: 814 times
- Contact:
- 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: Wrong 18F25K22 FCD Timer Definition
Right here are the updated files.
- Attachments
-
- FCD_Generate_File.zip
- (246.66 KiB) Downloaded 270 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
Re: Wrong 18F25K22 FCD Timer Definition
hello,
sorry for my remarks, but if you select the TMR5CS1 bit for the T5CKI Pin, you should disable them if you want to change the clock source.
Otherwise you will get a wrong definition.
thanks
sorry for my remarks, but if you select the TMR5CS1 bit for the T5CKI Pin, you should disable them if you want to change the clock source.
Otherwise you will get a wrong definition.
Code: Select all
Opt1="Clock Source Select"
Opt1Cnt=3
Opt1_1="Internal clock (Fosc)"
Opt1_1Val="st_bit(intcon, PEIE);\nst_bit(t5con, TMR5ON);\nst_bit(t5con, TMR5CS0);\ncr_bit(t5con, TMR5CS1);\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon, PEIE);\nst_bit(t5con, TMR5ON);\ncr_bit(t5con, TMR5CS0);\ncr_bit(t5con, TMR5CS1);\n"
Opt1_3="T5CKI Pin"
Opt1_3Val="st_bit(intcon, PEIE);\nst_bit(t5con, TMR5ON);\ncr_bit(t5con, TMR5CS0);\nst_bit(t5con, TMR5CS1);\ncr_bit(t5con, T5SOSCEN);\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:
Re: Wrong 18F25K22 FCD Timer Definition
Hello,
Good call, I will make the changes you proposed to the files.
Good call, I will make the changes you proposed to the files.
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: Wrong 18F25K22 FCD Timer Definition
Update,
a new failure:
orginal file:
correct file:
Now TMR4 works correct. Please update the relevant files.
kind regards,
Jojo
a new failure:
orginal file:
Code: Select all
[TMR4]
Name="TMR4"
......
EnableCode="st_bit(pie3, TMR4IE);\n"
DisableCode="cr_bit(pie3, TMR4IE);\n"
Code: Select all
[TMR4]
Name="TMR4"
.....
EnableCode="st_bit(pie5, TMR4IE);\n"
DisableCode="cr_bit(pie5, TMR4IE);\n"
kind regards,
Jojo