KV11Z_How to precisely configure time and execute?

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

KV11Z_How to precisely configure time and execute?

568 Views
le27
Contributor I

Hi all,I am new to the program, and I have encountered some problems when using KV11Z recently.
I use functions like: UART and RTS control, CAN, PWM and duty cycle on IDE.
Tested the functionality individually, everything works and performs as expected. But when I integrate it into the same program test, some problems will occur, as follows: I need to have an output that continuously generates a fixed frequency PWM, and at the same time send and receive signals from the external device through UART0 RTS,
UART1 sends and receives signals, and communicates with external controllers by CAN.

During the process, the oscilloscope observed that the PWM signal will be unstable, resulting in the frequency or duty ctcle not being able to output stably according to the settings. Searching for relevant information on the Internet and forums, it seems that there is no sorting of the working time for the functions to be executed. I have tried to use the timer method to modify it, but I did not get good results. The following is the code of my PWM and timer test, I hope Thanks in advance for assistance and advice from experts or people who have had the same problem and have already solved it.

The ultimate goal is to perform functions according to the set time as shown in the picture or not to conflict and affect the work.(The time in the picture is hypothetical)

圖片2.jpg

 

0 Kudos
Reply
1 Reply

557 Views
bobpaddock
Senior Contributor III

Interrupt processing takes time and setting/clearing flags with busy loops will lead to these results.

Structure the code so the hardware is doing as much as possible for you.
Try to get to set-and-forget PWM at the hardware level.

Also it is better to increment a variable in the IRQ and then compare it to saved value in the main loop.
This avoids the inherent race conditions of flags being set in the IRQ and cleared in the main loop, which will make for unstable outputs over long time spans.

A RTOS might help you.
I've usually managed to do without them by structuring the code as run-to-completion state machines.



0 Kudos
Reply