LIN Integration in BLDC Sensorless Code

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LIN Integration in BLDC Sensorless Code

Jump to solution
1,252 Views
blukacs
Contributor II

Hello,

I am trying to implement LIN functionality in the S12 BLDC Sensorless Motor control code. Upon start-up the motor should spin at 1000RPM. When integrating the LIN portion of the code the motor can no longer be controlled. From my testing the problem appears to be the Timer initialization through LIN in lin_lld_timesrv.c, specifically with channel 2:

Spoiler
#if (_MCU_ == _S12_)
void lin_lld_timer_S12_init
(
void
)
{
...

#if (defined(_MC9S12ZVML128_H) || defined(_MC9S12ZVL32_H)||defined(_MC9S12ZVHY64_H)||defined(_MC9S12ZVH128_H))
/*Configure the timer*/
// TIM0TSCR2 = 0x08; /*Timer prescaler = 32 (6.25MHZ/32 ~ 5.12[us]) */
TIM0TIOS_IOS2 = 1; /*Enable Channel 2 as Output Compare */
TIM0TIE_C2I = 1; /*Enable Channel 2 interrupt */
TIM0TC2 = (MCU_BUS_FREQ/1000000)*TIME_BASE_PERIOD;
TIM0TSCR1_TSFRZ = 1; /*Disable the timer when the MCU is in freeze mode */
TIM0TSCR1_TEN = 1; /*Enable the Timer */
#endif
...
}

If Channel 2 is enabled as an output compare with interrupts the motor functionality is lost. Commenting out either line of the code resolves the issue so my best guess is that an interrupt is flagged which never exits, hanging the program. I would like to debug further in codewarrior and check the registers and see if any interrupts are active. However, the debugger seems to not be able to handle the LIN module, as incorporating it causes a CRC issue when attempting to initiate a debug session so I'm at a bit of an impasse. 

Spoiler
INF: Calculated CRC-16 does not match block. (File = $6DE7, Device = $A66B)
ERR: Error verifying flash of device
ERR: Error occured during Flash programming.

For reference, I have generated the LIN configuration(ldf and npf) portion following the reference from 'AN5122-Using NXP’s LIN Driver with the MagniV Family' and taken the LIN source code from the example code from "Develop LIN-based Actuator Applications with Mixed-signal MCUs" webinar

If anyone has questions or suggestions please reach out. Thanks.

0 Kudos
Reply
1 Solution
1,041 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @blukacs,

I'm sorry for the delay.

Hard to say why the debugger crashers with that error, seems like this is not a runtime error after all.

Maybe you can start over with this application note:

Integrating the LIN driver with BLDC sensorless motor controller

https://www.nxp.com/docs/en/application-note/AN5201.pdf

AN5201SW attached

 

Regards,

Daniel

View solution in original post

0 Kudos
Reply
4 Replies
1,216 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @blukacs,

The BLDC demo uses Tim_Ch0 and Tim_Ch3, while the LIN driver Tim_Ch0 by default.

I understand you moved the LIN scheduler to Tim_Ch2, there should be no problem.

Can you test the Tim_Ch2 configuration stand-alone in a new project, or just the LIN driver with the Tim_Ch2 without the BLDC demo SW?

If I would guess based on the description, the execution runs away.

Can you implement something like this interrupt catcher to see if there is a machine exception, SPARE, TRAP, SWI, Spurious interrupt, etc instead of the Tim_Ch2?

https://community.nxp.com/t5/S12-MagniV-Microcontrollers/S12Z-Interrupt-catcher-for-unexpected-inter...

 

Regards,

Daniel

 

0 Kudos
Reply
1,102 Views
blukacs
Contributor II

Hi Daniel,

Thanks for the feedback and apologies for the late response. 

I would take credit but the LIN scheduler came configured on Timer channel 2. It's the same story for the timer channels of the BLDC demo code. 

I have tested a simple program that is only using the LIN driver (no BLDC control) to to read an up_down signal and report the status. In this case the program executes without issue. 

I can try implementing the interrupt catcher code provided, though won't I still need the debugger to test? I haven't been able to use the debugger with the LIN drivers, thought I haven't tested it on a standalone LIN application yet.

0 Kudos
Reply
1,042 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @blukacs,

I'm sorry for the delay.

Hard to say why the debugger crashers with that error, seems like this is not a runtime error after all.

Maybe you can start over with this application note:

Integrating the LIN driver with BLDC sensorless motor controller

https://www.nxp.com/docs/en/application-note/AN5201.pdf

AN5201SW attached

 

Regards,

Daniel

0 Kudos
Reply
963 Views
blukacs
Contributor II

Hi Daniel,

This example worked for me. Now to figure out the differences between my implementation. Thanks very much.