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?
Does any body have any suggestions for my application?
Any help is greatly appreciated.
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.
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.
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,
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.
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.
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.
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.
My first question remains the same. Is there any alternatives for my application other then LPTMR?
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
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.
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:
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.
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: