cancel
Showing results for 
Search instead for 
Did you mean: 

Can you sync ADC and PWM with phase delay?

alexandre239955_st
Associate
Posted on January 06, 2011 at 11:26

Can you sync ADC and PWM with phase delay?

#stm32 #stm32-adc #stm32-pwm
4 REPLIES 4
picguy2
Associate II
Posted on May 17, 2011 at 14:20

PWM comes from a timer.  I just looked at the general purpose timers.  But other timers may work as well.  Assuming you are not using all the capture / compare registers set a free one to generate an ADC trigger at the right time.  It’s not strictly phase delay but it just might work.

alexandre239955_st
Associate
Posted on May 17, 2011 at 14:20

Hi, 

Thanks for your reply. 

So, if I did understood, I should setup the PWM on one CC channel and use another CC channel to trig the ADC conversions in injected mode with the compare value that correspond to the delay. 

But what if I want to setup the PWM in center-aligned mode?

I initially intended to route several Timers to generate a phase delay and time base.

Let me know if I'm good on this point. I would be very greatful if you had any sources to provide. 

Alex

picguy2
Associate II
Posted on May 17, 2011 at 14:20

No sources except to say learn the processor and think.

You have a timer that generates pulses.  You want to trigger ADC conversion events synchronized to your pulse generation.  If a CC on the timer is available to make trigger generation easier use it.  If not, use another timer and keep them running together.  Or use external hardware to pull a line that triggers ADC conversion.

Life gets tricky if you need to vary the PWM frequency.

On the subject of Software Design Specifications: don’t make the mistake of specifying something that can’t be implemented.  Mr. PICguy recommends actually implementing the hard parts to prove that they can, in fact, be done.  And that you can do it.

If you hired me I would start by understanding what you are trying to accomplish with a Cortex processor.  Big picture first.  Then all of those parts that involve sensing or controlling external hardware have to fit into the big picture.  Do you have enough timers, ADC inputs, GPIO, PWM and whatever to do the big picture.  Power budget.  Processor clock budget.  Cost budget.  That kind of stuff.

I am a bottom up software guy.  I do critical low-level code first.  If the low-level command and control can’t work then the product can’t work.  It’s better to know that sooner rather than later.  

This the wrong place to recount horror stories of software failure brought on by design decision failure.  

Parting platitude: Quality is not about adherence to design documents or specs.  Quality is your products’ perception in the mind of the customer. 
regmaster2
Associate II
Posted on May 17, 2011 at 14:20

As PICguy said, it is important to know what you want to accomplish.

The timers of the STM32 are very versatile. You can also connect two timers in a master-slave configuration.

But you will always have delays.

I just made a project where I had to measure the power output of my pwm.

So I just scanned two complete pwm phases with adc using dma. At the end I calculate the average of the read values.

By that I get the actual current consumption and not just some peaks or lows.