Timer 1 interrupt

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Timer 1 interrupt

Post by Dave S »

Flowcode V 4.5 PIC16F887

Hi,

I am using a TMR1 interrupt activated from the internal clock. When this is enabled Flowcode sets the LP Oscillator,
(st_bit(t1con,T1OSCEN);), which causes RC0 and RC1 to be set as inputs. I am outputing PWM on RC1 (CCP2). I can rectify all this using C code each time the interrupt is enabled but is there a way to alter the Flowcode TMR1 interrupt code?

Why does this bit set in the first place if internal clock is set?

Thanks,

Dave.

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: Timer 1 interrupt

Post by Enamul »

Hi
Can you post your code so that we look exactly what is happening?
Enamul
University of Nottingham
enamul4mm@gmail.com

Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Re: Timer 1 interrupt

Post by Dave S »

Hi Enamul,

The code is large and commercially sensitive.

The C generated by flowcode is:

Code: Select all

//Interrupt
			//Interrupt: Enable TMR1
			st_bit(intcon,PEIE);
			st_bit(t1con,T1OSCEN);
			st_bit(t1con,TMR1ON);
			cr_bit(t1con,TMR1CS);
			t1con = t1con & 0x0F;
			st_bit(intcon,GIE);
			st_bit(pie1, TMR1IE);
The line st_bit(t1con,T1OSCEN); turns on the LP oscillator which is not needed for internal clock (fOsc/4) source.

How to stop it being generated?

Dave

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: Timer 1 interrupt

Post by Enamul »

Ok. No problem. I want to see the code as it is Flowcode v4 not v5. In V5 it is easy to edit without going to FCD but in V4 you have to edit in FCD. so please find out PIC16f887.FCD file in v4 FCD folder in program files. you should be able to find out the following piece of code..

Code: Select all

[TMR1]
;NOTE: this osc is enabled and turned on as part of the Opt1 code
Name="TMR1"
FlagReg=
FlagBit=
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\t\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"
UseExplicitHandlerCode=1
UseExplicitEnableCode=1
EnReg=
EnBit=
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="Transition on T1CKI pin"
Opt1_1Val="st_bit(intcon,PEIE);\nst_bit(t1con,T1OSCEN);\nst_bit(t1con,TMR1ON);\nst_bit(t1con,TMR1CS);\n"
Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon,PEIE);\nst_bit(t1con,T1OSCEN);\nst_bit(t1con,TMR1ON);\ncr_bit(t1con,TMR1CS);\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"
Change to the following in the Opt1_2 portion

Code: Select all

Opt1_2="Internal clock (Fosc/4)"
Opt1_2Val="st_bit(intcon,PEIE);\nst_bit(t1con,TMR1ON);\ncr_bit(t1con,TMR1CS);\n"
Let me know how it's going. I haven't got enough time to look at datasheet to verify whether it's the only way or not. Seems you are competent :)
Edit:Need to restart flow-code to have the effect of change in FCD.
Enamul
University of Nottingham
enamul4mm@gmail.com

Dave S
Posts: 39
Joined: Tue Jun 07, 2011 12:37 pm
Has thanked: 12 times
Been thanked: 5 times
Contact:

Re: Timer 1 interrupt

Post by Dave S »

Thanks very much Enamul. Is there a manual for all this stuff is is it just trial and error?

Thanks again,

Dave.

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: Timer 1 interrupt

Post by Enamul »

Actually in Flowcode couple of things are in FCD and most are in component c code. There is no clear guide line where you can get this kind of problem's solution yet; but spending couple of week in forum I believe you will know where to look for. I am in the forum for last 4 months so it's not that much tough to know.
If you know where to look then it will not be trial and error issue rather you can dig that out easily.
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply