cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Controlled by ADC conversion

gdiez
Associate II
Posted on August 23, 2010 at 12:02

PWM Controlled by ADC conversion

8 REPLIES 8
gdiez
Associate II
Posted on May 17, 2011 at 14:03

Any one have developed something similar? Or I´m so confused that it cant´be done? I think that is possible to define the PWM signal after the ADC conversion finishes. I´ll almost try it, because my job depends on it hahaha.

I´ll post my result here of course 🙂

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

ADC done -> ISR -> do whatever to PWM -> restart ADC -> exit ISR.

Timing: 12 clocks from ADC done to ISR.  Perhaps another dozen to PWM change.  At a 72 MHz processor clock this 0.33 microseconds delay.  I would write the ISR in assembly, but that’s just me.  Expect longer times using the STM32 library.  

Or do I not understand what you need to do?

gdiez
Associate II
Posted on May 17, 2011 at 14:03

Hello PicGuy:

Thkas for reply. What I want to do is:

1.- Init 20KHz ADC conversion

2.- Wait ADC conversion Time (1uS in my project)

3.- Launch the TIM1 PWM with 20KHz

4.- Make another ADC conversion

That is what I want to do. An Image is better than one thousand of words.

0690X00000602OxQAI.bmp

Some Engineer of my departament says that the EOC(End of conversion ADC flag) must enter into a ISR, that is which must launch the PWM. He?s said me that it will be transparent for me with TIM1 Advanced Control Timer only I?ve to do is configure it

gdiez
Associate II
Posted on May 17, 2011 at 14:03

suggestion??

disirio2
Senior
Posted on May 17, 2011 at 14:03

I would make it a bit differently.

1 - Activate a PWM and make it generate a periodic interrupt on the timer overflow.

2 - From the PWM ISR start the ADC conversion.

3 - On the ADC end-of-conversion interrupt, read the result and change the PWM duty cycle, stop the ADC.

PWM and ADC conversion would happen at the same time and not sequentially because the ADC conversion time is much shorter than the PWM cycle time.

Giovanni

---

ChibiOS/RT - http://chibios.sourceforge.net

gdiez
Associate II
Posted on May 17, 2011 at 14:03

Hi giovanni:

I will do like you say. Do you have code to do it? I´m newbie in STM32 and I am not enough good yet to program it.

Thanks anyways

disirio2
Senior
Posted on May 17, 2011 at 14:03

Hi Gerardo,

You may look at the project in my signature, incidentally it has an ADC and PWM drivers (and others) for STM32.

Probably an RTOS is too much for that simple application but you could give a look at the device drivers implementation and take some code there.

Probably I will add a demo that does exactly that when I will have some time, it should be a good example but I can't make promises on when.

Giovanni

---

ChibiOS/RT - http://chibios.sourceforge.net

gdiez
Associate II
Posted on May 17, 2011 at 14:03

Woow Giovanni.

It would be fantastic to see this work done. I will check your web. When I have finished this i will mail you to give my advances.

Thks