How to setup ADC to high part of PWM duty cycle on a HCS08

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

How to setup ADC to high part of PWM duty cycle on a HCS08

1,206 Views
etanner
Contributor I

I have my ADC reading a few different things using the ADC conversion complete interrupt.

 

What I need is to measure at Voltage to the Motor.  A PWM from the MCU is driving a motor control circuit.  How do I ensure I am reading the High part of the PWM duty cycle, While still, periodically read the other analog values on separate analog input channels?

 

Thanks,  

Labels (1)
0 Kudos
Reply
1 Reply

689 Views
bigmac
Specialist III

Hello, and welcome to the forum.

 

One method would be to enable overflow interrupts for the TPM module that generates the PWM signal.  The overflow interrupt would then occur immediately after the PWM signal changed state.  Within the overflow ISR you would start a new ADC reading, and immediately exit the ISR.  Then use the ADC interrupt to read the result in the normal manner.

 

On the other hand, if you required to start the measurement some time after the PWM signal changed state, perhaps to avoid coinciding with a voltage spike or "ringing", you might utilize another output compare channel on the same TPM module.  The channel value setting would determing the amount of delay until the interrupt occurred.  Of course, this delay must alway be less than the minimum pulse width applied to the motor.

 

To synchronise the other ADC measurements, so that they do not coincide with the time critical measurement, you might set a flag at the same time the time critical measurement is started.  Then within the ADC ISR, the flag would indicate that the current result was the time critical measurement one.  The ADC ISR would clear the flag, and commence a new sequence of non-critical measurements.

 

Regards,

Mac

 

0 Kudos
Reply