MC68HC908QL4: PWM doesn't work together with any CHxIE enabled!

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC68HC908QL4: PWM doesn't work together with any CHxIE enabled!

3,055 次查看
Yac
Contributor I
Hello everybody,

I've got a problem with PWM - it doesn't work when I enable timer interrupts.
I have just programmed the PWM on the channel 0, and I wanted to have an ISR to be called when output compare occurs on channel 1.
I have done the following steps:
1. Define an ISR function: it just resets the timer channel flag.
#pragma TRAP_PROC
void TIM_ISR(void)
{

TSC1; // read TIM channel status and control
TSC1_CH1F = 0; // clear timer channel flag

}

2. Add this ISR function to the interrupt vector:
void *const _vectab[] =
{
LIN_VECTF NULL, /* 0xFFDE ADC */
LIN_VECTF NULL, /* 0xFFE0 Keyboard */
LIN_VECTF NULL, /* 0xFFE2 Reserved */
LIN_VECTF NULL, /* 0xFFE4 Reserved */
LIN_VECTF NULL, /* 0xFFE6 Reserved */
LIN_VECTF NULL, /* 0xFFE8 Reserved */
LIN_VECTF SLIC_ISR, /* 0xFFEA SLIC */
LIN_VECTF NULL, /* 0xFFEC Reserved */
LIN_VECTF NULL, /* 0xFFEE Reserved */
LIN_VECTF NULL, /* 0xFFF0 Reserved */
LIN_VECTF NULL, /* 0xFFF2 TIMER overflow */
LIN_VECTF TIM_ISR, /* 0xFFF4 TIMER channel 1 */
LIN_VECTF NULL, /* 0xFFF6 TIMER channel 0 */
LIN_VECTF NULL, /* 0xFFF8 Reserved */
LIN_VECTF NULL, /* 0xFFFA IRQ */
LIN_VECTF NULL, /* 0xFFFC SWI */
LIN_VECTF _Startup /* 0xFFFE RESET */
};

3. Enable the interrupt in the main function:
TSC1_CH1IE = 1;

When the interrupt from channel 1 isn't enabled, the PWM based upon the channel 0 works correctly, but as soon as I enable this interrupt then the whole PWM stops working.
What do I wrong? Maybe should I do some additional things in ISR?

TIA,
Yac.
标签 (1)
0 项奖励
回复
4 回复数

637 次查看
bigmac
Specialist III

Hello Yac,

Are you using bufferered or unbuffered PWM.  I am not sure about the 908QL4, but for other devices that use the TIM, when buffered PWM is used, timer channels 0 and 1 are linked.  I wonder if this is the problem you are observing.

Regards,
Mac

 

0 项奖励
回复

637 次查看
Yac
Contributor I
Hi Mac,
I am just using the unbuffered PWM. I have done some tests in meantime and I have noticed that the main code of program doesn't work when I enable the CHxIE interrupt, this means, that I have a simple test loop in main() that do practically nothing but looping, and when the CHxIE is disabled then the LED on PCB shines a little bit accordingly to low duty cycle, and program runs correctly in loop, but when I set the CHxIE as enabled, then the program goes to loop, makes maybe 1-2 iterations under debugger and then goes to strange place where all memory addresses are filled with 0xCDCD, and additionally I have an error message: "Last RESET caused by Illegal opcode executed.".
I think this problem is connected with ISR function. Maybe the microcontroller doesn't know that I have already defined the ISR for Timer? But it's strange, since I have set the address of ISR to interrupt vector and also the ISR function is defined and it should be simply called and returned from it.

Best regards,
Yac.
0 项奖励
回复

637 次查看
peg
Senior Contributor IV

Hi Yac,

Just a thought. Does your ISR compile into code that satisfies the requirements to clear the interrupt flag?

Regards David

 

0 项奖励
回复

637 次查看
Yac
Contributor I
Hi David,

Yes, I reset this interrupt flag in my ISR, but the problem is that the ISR is never called!
I have anyway located the problem - it lies probably in CodeWarrior compiler. Namely there is a file called vector.c, where the interrupt vector is defined and I thought I should set the appropriate element of the vector to my ISR, and so I did but it didn't work as I written before. I just looked at the memory dump and there was just 0xFFFF in the place where the ISR address should be.
But I have found also another place where the user can (and should) set his ISR address, and it is a project file called "Project.prm". There is a command to use called "VECTOR" with parameters like ISR position (address) and ISR name. Than the program is correctly compiled and the memory is correctly filled with the ISR address.
Well, then my question is: why do we want this funny vector.c file since it makes just nothing to the program? I have removed the ISR entry from it and replaced with NULL and left only VECTOR entry in project.prm and it worked also good, like before!

Best regards,
Yac.
0 项奖励
回复