Timer with a Trigger/ISR depending on a changing set time variable

cancel
Showing results for 
Search instead for 
Did you mean: 

Timer with a Trigger/ISR depending on a changing set time variable

633 Views
Sam_ECU
Contributor III

Hello,

I have an application where I would like to generate a trigger / interrupt after a certain amount of time, but the defined time period is constantly changing in the system.

(Measuring a flywheel with 12 teeth and extrapolating the crank angle from the last tooth using the last measured period between the last two teeth until the next tooth is measured)

I've looked through the MBD-Toolbox and the examples and can't find anything suitable.

The closest I can find is the LPTMR and potentially the Set Compare Value Block, but it doesn't appear to work as I expect.  The example "lptmr_complex_time_counter_s32k14x.slx" doesn't work as described on my board. 

Does the Set Compare Value Block overwrite the Compare Value in the LPTMR Config?

Sam_ECU_0-1631218396710.png

Does any body have any suggestions for my application?

Any help is greatly appreciated.

0 Kudos
11 Replies

584 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Sam_ECU ,

Indeed the LPTMR Set Compare Value is changing the internal compare register for the LPTMR. When you use this block, this will stop the LPTMR, update the Compare value and then Start the LPTMR counter again.

Now, you are right, I've tried the example out of the box, and seems to not work as in the description. But the issue here is that initially, the model has been developed in R2016a I think, and now I've tried in R2018a and the code was generated in a  different order. See below. Basically, the new compare value as updated before computing the new one. 

mariuslucianand_1-1631707701359.png

 

After changing the block's priorities, on how the Simulink should generate value, the code has been generated in the right order, and the model works as expected. 

mariuslucianand_2-1631707808420.png

The Read compare value should work the same either if you call the block inside the interrupt or not. However, if you use this block inside the interrupt it matters if the generated code reads the value before or after you call the update to compare value.

I've understood, that Channel 0 for the LPTMR sets the Timer within Simulink.

Not quite. The LPIT channel 0 is used for the Model timer. LPIT is a different timer than LPTMR. LPIT has up to 4 channels, while LPTMR has only one channel, the one in use.  

For the FreeMaster issue I cannot reproduce, can you send us the project, please?

Hope this helps,

Marius

 

0 Kudos

575 Views
Sam_ECU
Contributor III

Hallo @luc 

Cheers.

My mistake, I meant to write the LPIT governs the Model Timer.

Have I understood correctly, that LPIT can only be set once and can't be dynamically updated within MBDT? (Eg. with a "Set" Block)

Have I also understood correctly, that LPTMR is potentially the only option in MBDT, that can deliver my aim for a timer that can be adjusted by the application?

I've attached 4 files.

Sam_ECU_0-1631733665720.png

The Freemaster file I use with each of the three simulink models.

"CB125_Crk_Spd_Sens_Works.slx" works in Freemaster without issue.  (The LPTMR is in the model and works without issue and after being set by a constant value)

"CB125_Crk_Spd_Sens_DoesntWork_LPTMR" immediately looses connection with the board in Freemaster. (The LPTMR Set Block is updated by the calculation for the Time per Crank Tooth.)

"CB125_Crk_Spd_Sens_DoesntWork_TemporalLogic" generates correct data for some, incorrect for the others data in Freemaster.  Then after several seconds it looses connection with the board. (I've the aim to use time outs in Stateflow)

 

I've a strong suspician that the issue maybe linked to another issue I posted within the Freemasterforum.  Either way, I appreciate the help.

https://community.nxp.com/t5/FreeMASTER/Freemaster-Timesout-ERROR-code-0x80000101-with-MBDT-Examples...

0 Kudos

469 Views
Sam_ECU
Contributor III

Hallo @mariuslucianand 

Have you had a chance to look at the issue?

0 Kudos

574 Views
Sam_ECU
Contributor III

P.S. I'm working with Matlab 2018.

0 Kudos

543 Views
Sam_ECU
Contributor III

Hallo @mariuslucianand 

Have you had a chance to look further into the issue?

I've reinstalled Freemaster, the problems remain. When using the recorder as soon as it's triggered, the board times out with Freemaster.

0 Kudos

431 Views
mariuslucianand
NXP Employee
NXP Employee

Hello @Sam_ECU 

We could not reproduce the reported behavior on our side. Can you please try with different baud rates on FreeMaster?

Regards,

Marius

0 Kudos

349 Views
Sam_ECU
Contributor III

Hallo @mariuslucianand 

Trying with different Baudrates, the problem remains the same.

Playing around with the model, the issue is dependent to changes within the model.  Eg. Adding an extra MBDT Block.

0 Kudos

251 Views
Sam_ECU
Contributor III

Hello @mariuslucianand 

I've been playing further with the LPTMR for my application.  The timeout issue within Freemaster + Code not working is 100% linked to the settings of the LPTMR Config Block.

Attached you'll find two files.  The first works without issue, but the LPTMR_Clk is to slow for my application. 

In the second file the initial compare value for the LPTMR is changed from 1,000,000 --> 10,000.

Sam_ECU_1-1635513721269.png

 -->

Sam_ECU_0-1635513678965.png

The application is fine until it receives the first ISR from the FTM-Module.  (For your testing you'd have to input a signal to the FTM-Module and change the activation settings for the LPTMR.)

What's the issue?

0 Kudos

139 Views
Sam_ECU
Contributor III

Hello @mariuslucianand 

Have you had a chance to look at this particular issue?

0 Kudos

618 Views
Sam_ECU
Contributor III

Hello All,

Additional Information from me in case someone is following this topic.  The LPTMR example above works, but to read the compare value it has to be in a higher level then the subsystem.  Reading the compare value within the subsystem is what led me to believe the example was working as intended.

Sam_ECU_0-1631512345479.png

My first question remains the same.  Is there any alternatives for my application other then LPTMR?

0 Kudos

604 Views
Sam_ECU
Contributor III

Hello All,

I've been trying to understand the LPTMR but just keep running into issues and would appreciate any and all help.

I've understood, that Channel 0 for the LPTMR sets the Timer within Simulink

Sam_ECU_0-1631599825536.png

When I set up a Stateflow with temporal logic, the application works for ~30 secs and then Freemaster appears to loose connection to the board.

Sam_ECU_4-1631600195462.pngSam_ECU_5-1631600225570.png

 

Sam_ECU_1-1631599965414.png

 

If I try and use the LPTMR Channel 1 with the "Set Compare Value" block, as long as the "Set Compare Value" is defined within the ISR Function (from a constant) everything (including Freemaster) works without issue:

Sam_ECU_2-1631600107331.pngSam_ECU_3-1631600132370.png

 

But as I want my timer to be set by changing external conditions, I try to input my calculated value into the ISR-Function to set the compare value, but connection to the board is lost in Freemaster.

Sam_ECU_6-1631600482098.pngSam_ECU_7-1631600515261.png

I can output the timer to a GPIO a measure the set value with an oscilloscope and it appears that the code is working correctly.

I've tried defining the Set Compare Value outside of the LPTMR-ISR-Function.  The issue remains the same:

 

Sam_ECU_9-1631600935572.pngSam_ECU_10-1631600947255.png

Sam_ECU_8-1631600917028.png

Thanks,

Sam

 

0 Kudos