Hi Guys,
this is my first Project with a Freescale K60 uC
I've got a Problem with the Overflow Interrupt on FTM0. I want to jump in the ftm0_isr when the timer reaches the module value, but it doesn't.
Can anybody help me?
I attached the main.c. Thanks in advance
Original Attachment has been moved to: main.c.zip
解決済! 解決策の投稿を見る。
Hi Andreas,
You commented out a printf() in the void enable_irq(int irq) routine that caused the div calculation to be in error (it pulled the div = irq/32; into the if statement).
if (irq > 91)
//printf("\nERR! Invalid IRQ value passed to enable irq function!\n");
/* Determine which of the NVICISERs corresponds to the irq */
div = irq/32;
Changing the code to:
if (irq > 91)
asm(" nop"); //DES Must have an instruction after the "if() statement or using {} to indicate no instruction. With printf commented out div was not calculated correctly.
OR (better solution)
if (irq > 91)
{
//printf("\nERR! Invalid IRQ value passed to enable irq function!\n");
}
fixes the issue.
I also changed how the LED_PORT toggle was operating by following:
#define LED_PORT_T GPIOA_PTOR //DES toggle port pin control
LED_PORT_T |= (1<<LED_GREEN);
Regards,
David
Hi Andreas,
I've attached "C" file that has code to initialize the FTM to generate an TOF interrupt.
Look for this snippet in the source file:
//DES 1=test, 0=default code. Note: FTM defaults to a 16-bit counter...trying to generate TOF interrupt
{
unsigned int initialized;
_ftm1_enable_clock(); //enable clock to FTM1 module
FTM1_MODE = (FTM_MODE_WPDIS_MASK | FTM_MODE_FTMEN_MASK); //Write protection is disabled and all registers are available with no restrictions
FTM1_CNTIN = FTM_CNTIN_INIT(0); //Initial Value of the FTM Counter
FTM1_SC = (FTM_SC_TOF_MASK | FTM_SC_TOIE_MASK | FTM_SC_PS(6)); //FTM counter has overflowed,Enable TOF interrupts,Divide by 6=64 ...default count up mode
FTM1_MOD = FTM_MOD_MOD(0xdcba); //Modulo value
_int_install_isr(INT_FTM1, (void (_CODE_PTR_)(pointer))FTM1_ISR_TEST, NULL);
initialized = _cortex_int_init(INT_FTM1, 7, TRUE);
initialized = _cortex_int_enable(INT_FTM1); //wants IRQ # not Vector #....a pain.
FTM1_PWMLOAD = 0x200; //DES test
FTM1_SC |= ( FTM_SC_CLKS(1) ); //System clock(clock selection starts the counting process)
}
Hope this helps.
Regards,
David
Hi David,
Thanks a lot. I forgot to set FTM_SC_TOF_MASK
But I think there is another Problem. The Interrupt Service Routine has to be set in the Interrupt table.
I have no idea how this is done. I've seen some example Projects, but this looks pretty confusing to me.
i don't want to replace the whole kinetis_sysinit.c
I attached my kinetis_sysinit.c for you
I'll be back in the Laboratory on Wednesday. I hope i can figure it out then.
Have a good Weekend,
best regards,
Andreas
Hi Andreas,
Good news and thanks for good weekend wises.
you are on the right track for the baremetal coding approach. You do want to insert the address of the ISR into the vector table.
The Freescale SC code has the vector table as:
#define VECTOR_078 default_isr // 0x0000_0138 78 62 FTM0 Single interrupt vector for all sources
#define VECTOR_079 default_isr // 0x0000_013C 79 63 FTM1 Single interrupt vector for all sources
#define VECTOR_080 default_isr // 0x0000_0140 80 64 FTM2 Single interrupt vector for all sources
The K60 product page has a Download link to the SC code base for CW and IAR:
Hope you have a godd weekend too.
Regards,
David
Hi David,
i took your advice and inserted the isr in the vector table, but it doesn't work so far.
The PWM Signal runs blameless, but the ISR is never called. The LED should light up in the ISR.
Could you please take a look at my sources. Maybe you can find the mistake.
Thanks,
Andreas
Hi Andreas,
You commented out a printf() in the void enable_irq(int irq) routine that caused the div calculation to be in error (it pulled the div = irq/32; into the if statement).
if (irq > 91)
//printf("\nERR! Invalid IRQ value passed to enable irq function!\n");
/* Determine which of the NVICISERs corresponds to the irq */
div = irq/32;
Changing the code to:
if (irq > 91)
asm(" nop"); //DES Must have an instruction after the "if() statement or using {} to indicate no instruction. With printf commented out div was not calculated correctly.
OR (better solution)
if (irq > 91)
{
//printf("\nERR! Invalid IRQ value passed to enable irq function!\n");
}
fixes the issue.
I also changed how the LED_PORT toggle was operating by following:
#define LED_PORT_T GPIOA_PTOR //DES toggle port pin control
LED_PORT_T |= (1<<LED_GREEN);
Regards,
David
Oh crap, what a bad mistake. my professor would kill me. I will try this tomorrow.Everything is going to be allright :smileywink:
Many thanks for your assistance.
Best regards,
Andreas