Synchronizing ADC conversion with PWM?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by apullin on Sun Jan 17 16:55:38 MST 2016
Hi folks,

Is there a way with the LPC17xx to sync or trigger an ADC sample & conversion from the start of the PWM period? Or end or the period, or the low-transition.

The application is to the speed control of a brushed DC motor. The ADC will sense the back EMF of the motor, ideally in the last 5% or so of the PWM period, and then PWM just gets limited to 95% maximum.

I am looking at the User Manual, and nothing it jumping out at me, but I am not familiar with LPC peripherals. I have previously implemented this on a dsPIC, but it has hardware support specially for this operation, where there is a "Special Event" counter triggered by the start of the PWM period, clocked by the PWM clock, and the expiration of that count can be used to initiate the ADC samp&conv.

It occurs to me that I could do this by using a timer with match registers to set period & duty cycle (output pins or interrupt + software GPIO), and then a third match register w/ interrupt to start the ADC with a software write.

Does that make sense?
Since I need 4x PWM w/ equal period, that should be doable with just 2x timers.

If there is a more clever or elegant way to put that together with functionality already existing in the LPC17xx peripherals that I have missed, please let me know!