PWM Port

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

PWM Port

1,518 Views
RoboMan
Contributor I
I was just confirming if I understand how the 8 PWM ports work on the HCS12.  I'm building a robot that uses GPS information to navigate a course.  It will have differential steering that will be controlled by PWM on each of the tires.  Now once the PWM duty cycle and frequency is set, will it affect the information being read into the GPS.  Now that may sound confusing, but I understand when an interrupt occurs, the CPU is interrupted.  Well if that occurs when serial data is being read in from the GPS, it might be interrupted in the middle of the read in of the serial data, making the data that was read in corrupt since it was interrupted while it was reading in data.  My question is when the PWM port is being used, is there no interrupts of the CPU that could cause the serial data to be corrupted? 
 
Thanks
 
Labels (1)
0 Kudos
1 Reply

291 Views
Lundin
Senior Contributor IV
You will only get interrupts from the PWM port in case you have enabled them. If you have written your program in a good way, all calculations are done before you receive the PWM interrupt and the only thing that you need to do upon reception is to copy down the new values into the PWM registers.

If you keep doing things during the reception of data from the SCI, you need to make sure you finish it before the next byte is sent. For example if you are running on 9600, you have 1/9600 * 10 bytes = 1ms as a minimum time before the next byte is expected.

If you want to let a lot of code run when an interrupt is triggered, but you worry about other processes that are running simultaneously, then 1) disable the interrupt source, 2) enable interrupts with CLI. Then you allow other interrupts to take precedence.

You can also set the HPRIO register to point at the most important interrupt, to avoid some code gitter. If several interrupts occur at once, the S12 will pick the one with the highest priority and the others will have to wait.
0 Kudos