Hi,
I am trying to control a DC brushed motor, i built a model in Simulink and it works fine and i can change the speed using the Freemaster. But now i am trying to add a Sine wave to it so i can hear a humming sound on the motor. each time when i run it, the connection to the freemaster is lost. i read some of the questions on your page tried to do some of the solutions but no results.
#S32K114EVB
PS. I am working on my Bachelor Thesis with this project and i have basic knowladge about NXP.
Hello @laith,
Thank you for your post!
I had a look at your model and I could notice some things that may cause the behavior that you are reporting.
1. First of all, it appears that the block for the Edge Capture interrupt is not triggered as shown below.
'
The way you have used it implies that the code inside the subsystem is executed on the main step of the model when it actually needs to be executed when the input Edge shall trigger the interrupt. In the below construction, the Simulink function inside the block will be executed when the rising-rising signal is triggered. The same is with the Dual Edge Capture Restart block. This shall be used inside the s-function triggered block to reset the input edge counter after triggered, otherwise, it will be triggered each step execution.
2. The second thing you have to take into account is the step frequency, related to what it needs to do. For example, in your model, the step frequency is 10kHz. I've noticed that the step mainly computes the new PWM duty cycle. But, the frequency of the PWM block is 5kHz. Basically, it tries to compute/update the duty cycle twice faster than a PWM period so you might try to adjust the model timing.
3. Please adjust the priorities of the interrupts. For example, the step interrupts timer trigger is set to 1. This is the higher priority for an interrupt on an ARM Cortex M core. For the FreeMaster, there are also 3 modes of operation: Polling, Short Interrupt, and Long Interrupt. The difference between these modes is how much code from the FreeMater transfer is executed on the UART interrupt. But in the model attached, the same value 1 for the priority is set in the FreeMaster block. So also, you might need to adjust the interrupt priorities, so that Step shall have the lowest interrupt priority, for example, 15, the Dual Edge capture shall have the next priority for example 12, and if the FreeMaster communication is smth you really need to achieve than you could set this the most priority interrupt. Please keep in mind that these numbers are just an example and not a reference.
Please let me know if any of the suggestions above worked on your side!
Regards,
Marius