Wrong 18F25K22 FCD Timer Definition

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Wrong 18F25K22 FCD Timer Definition

Postby Jojo1981 » Sun Jul 22, 2012 2:22 pm

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" <-- :wink:
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xE7) | 0x10;\n" <--- :wink:
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xE7) | 0x18;\n" <----- :wink:


Finally, the TMR5 definition is absolute wrong and you mask the wrong bits for the prescaler definition.

Thanks
These users thanked the author Jojo1981 for the post:
Enamul (Sun Jul 22, 2012 4:12 pm)
Rating: 5%
 

User avatar
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

Postby Enamul » Sun Jul 22, 2012 4:16 pm

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" <-- :wink:
Opt2_3="1:4"
Opt2_3Val="t5con = (t5con & 0xE7) | 0x10;\n" <--- :wink:
Opt2_4="1:8"
Opt2_4Val="t5con = (t5con & 0xE7) | 0x18;\n" <----- :wink:

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
Attachments
18f25k22.jpg
18f25k22.jpg (93.38 KiB) Viewed 4627 times
Enamul
University of Nottingham
enamul4mm@gmail.com

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: Wrong 18F25K22 FCD Timer Definition

Postby Jojo1981 » Sun Jul 22, 2012 7:05 pm

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

User avatar
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

Postby Enamul » Sun Jul 22, 2012 10:24 pm

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..

Code: Select all

MaxTimerOverflow=65536

Above is true for 16-bit...
but for 8-bit following should be..

Code: Select all

MaxTimerOverflow=256

Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: Wrong 18F25K22 FCD Timer Definition

Postby Jojo1981 » Mon Jul 23, 2012 7:08 am

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. :wink:

Kind regards,

User avatar
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

Postby Enamul » Mon Jul 23, 2012 11:07 am

Hi,
Yes! you are right. The above is true for TMR0 not for TMR1/3/5
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

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

Re: Wrong 18F25K22 FCD Timer Definition

Postby Benj » Mon Jul 23, 2012 11:37 am

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.

18F25K22.fcd
(24.23 KiB) Downloaded 141 times


Let me know if you spot any further issues.

Edit- Just spotted a bug in the timer 5 FCD code, damn, regenerating again :)
These users thanked the author Benj for the post:
Enamul (Mon Jul 23, 2012 1:02 pm)
Rating: 5%
 

User avatar
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

Postby Enamul » Mon Jul 23, 2012 1:03 pm

Hi,
Thanks Ben. :)
Enamul
Enamul
University of Nottingham
enamul4mm@gmail.com

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

Re: Wrong 18F25K22 FCD Timer Definition

Postby Benj » Mon Jul 23, 2012 1:38 pm

Right here are the updated files.
Attachments
FCD_Generate_File.zip
(246.66 KiB) Downloaded 114 times

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: Wrong 18F25K22 FCD Timer Definition

Postby Jojo1981 » Mon Jul 23, 2012 2:43 pm

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. :wink:
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

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

Re: Wrong 18F25K22 FCD Timer Definition

Postby Benj » Mon Jul 23, 2012 3:42 pm

Hello,

Good call, I will make the changes you proposed to the files. :D

Jojo1981
Posts: 28
Joined: Wed Feb 29, 2012 9:23 pm
Been thanked: 3 times
Contact:

Re: Wrong 18F25K22 FCD Timer Definition

Postby Jojo1981 » Thu Aug 09, 2012 6:39 pm

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