Page 1 of 1
Wrong 18F25K22 FCD Timer Definition
Posted: Sun Jul 22, 2012 2:22 pm
by Jojo1981
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
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Sun Jul 22, 2012 4:16 pm
by Enamul
Hi,
Thanks for the findings. You are absolutely right..
[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" <-----
The above code should be following..
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"
Ben please update that in master file..
Enamul
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Sun Jul 22, 2012 7:05 pm
by Jojo1981
Hello,
here a little bit more changes on the 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"
I hope you can use it for the master file
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Sun Jul 22, 2012 10:24 pm
by Enamul
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
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 7:08 am
by Jojo1981
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:
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.
I think it is better than the 8bit solution and the failure rate is lower than the 8bit instruction.
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,
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 11:07 am
by Enamul
Hi,
Yes! you are right. The above is true for TMR0 not for TMR1/3/5
Enamul
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 11:37 am
by Benj
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

Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 1:03 pm
by Enamul
Hi,
Thanks Ben.
Enamul
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 1:38 pm
by Benj
Right here are the updated files.
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 2:43 pm
by Jojo1981
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.
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"
thanks
Re: Wrong 18F25K22 FCD Timer Definition
Posted: Mon Jul 23, 2012 3:42 pm
by Benj
Hello,
Good call, I will make the changes you proposed to the files.

Re: Wrong 18F25K22 FCD Timer Definition
Posted: Thu Aug 09, 2012 6:39 pm
by Jojo1981
Update,
a new failure:
orginal file:
Code: Select all
[TMR4]
Name="TMR4"
......
EnableCode="st_bit(pie3, TMR4IE);\n"
DisableCode="cr_bit(pie3, TMR4IE);\n"
correct file:
Code: Select all
[TMR4]
Name="TMR4"
.....
EnableCode="st_bit(pie5, TMR4IE);\n"
DisableCode="cr_bit(pie5, TMR4IE);\n"
Now TMR4 works correct. Please update the relevant files.
kind regards,
Jojo