cancel
Showing results for 
Search instead for 
Did you mean: 

[HELP] STM32F4 generate PWM 3 channel shift phase 120 degree!

tranvanduy
Associate II
Posted on April 06, 2014 at 06:30

Hi all!

I want to control 3 phase motor (I get HDD motor from old HDD), and now I can generate 3 PWM signal on 3 channels but they are same, not

shift phase

120 degree!

Please help me!

I use STM32F4 discovery board and Keil!

Thanks all
40 REPLIES 40
aspire
Associate II
Posted on May 06, 2014 at 18:26

Posted on May 06, 2014 at 21:12

This wades into an area which I'm not particularly experienced with.

ST provides some examples of it's own, and the TIM units are described, somewhat obtusely, in the reference manual. You should review these to understand what they might be capable of.

My observation would be that lower frequency PWM (say sub 100 KHz) can be handled using the assorted TIM interrupts, and advancing the CCx trigger points by desired amounts. ie hardware signal placement with heavy software management.

Each TIM has a single counting element.

You can use multiple TIM units, and can adjust the phase relationship with each other. They will be synchronous with each other, sharing a common clock (view of time). You can trigger the ADCs from TIMs, a rate of 3x for the timebase would take samples at 120 degree offsets.

Diagram specific signals, timings and relationships, it is easier to interpret.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aspire
Associate II
Posted on June 26, 2014 at 06:08

Mr Clive1, may I ask you,,How to make a interleaved PWM like as in the picture (in attachemen)?may be the program based on keil.

________________

Attachments :

Full.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I02k&d=%2Fa%2F0X0000000bTT%2FdMaWMW6XldrHULKUaA1CG5iZLUeskdFjUqwRHHN.pVc&asPdf=false
Posted on June 26, 2014 at 17:31

Suggest you look at

STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\TIM\TIM_6Steps

You'd need to find a timer that offer inverse outputs ie (CH1, CH1N, etc), then I think you'd have to manage the placement of the edges, likely using toggle mode, and advancing the CCRx setting for the channel at the interrupt for each.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aspire
Associate II
Posted on August 08, 2014 at 10:30

yes Mr.Clive..now,,I can generate this pulsa, but I am not change the duty cycle which depend on input adc. by the way, how to make program for change duty cycle in three pulse?thanks you Mr.Clive

Posted on August 08, 2014 at 17:55

You'd want to alter the period, and to change the duty you'd need to actively manage the placement of the compare registers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aspire
Associate II
Posted on August 10, 2014 at 18:19

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6fa&d=%2Fa%2F0X0000000bsq%2FVBf8LSF.dIWKSsYl4JFDGC27afIsE07RrPHbq4Z5G04&asPdf=false
Posted on August 10, 2014 at 20:20

Like I said, you're going to actively manage the CCRx registers, under interrupt to alter the DUTY of the signal.

Toggle mode is going to intrinsically default to a 50/50 duty if you configure the registers in a passive sense. In an active mode you are going to explicitly program the position of each EDGE you want generating, and in doing so you can control the DUTY cycle.

The 0% setting is 0, all OFF, the 100% setting is 40000, all ON

Decide how many ADC channels you are using. If more that one, then you'll need to use DMA. For one you don't need to scan. You need to wait for each sample to be ready, and you should probably confirm to yourself that the reading you're getting is actually within the range you want.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
aspire
Associate II
Posted on August 11, 2014 at 01:28

hmm,,Ok Mr.Clive,,but Are you have a simple interrupt program to manage a duty cycle..?because I'm never use interrupt program,,still confusing,,hehehe

Ok Mr.Clive, thanks for your suggestion,,so this programe became this:

- I use adc3 for dma and use 4 chanel, because for sensing V,I input and V,I output

void ADC3_DMA2_Config(void)

{

  ADC_InitTypeDef       ADC_InitStructure;  

  ADC_CommonInitTypeDef ADC_CommonInitStructure;

  DMA_InitTypeDef       DMA_InitStructure;   

  GPIO_InitTypeDef      GPIO_InitStructure;  

  /* Enable ADC3, DMA2 and GPIO clocks ****************************************/

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);

  /* DMA2 Stream0 channel0 configuration **************************************/

  DMA_InitStructure.DMA_Channel = DMA_Channel_2; 

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS;

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&read_adc; 

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 4; // isi untuk banyaknya channel

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;         

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA2_Stream0, &DMA_InitStructure);

  DMA_Cmd(DMA2_Stream0, ENABLE);

  /* Configure ADC3 Channel_0,1,2,3 pin as analog input ******************************/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* ADC Common Init **********************************************************/

  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_15Cycles;

  ADC_CommonInit(&ADC_CommonInitStructure);

  /* ADC3 Init ****************************************************************/

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfConversion = 4; 

  ADC_Init(ADC3, &ADC_InitStructure);

  /* ADC3 regular channel12 configuration *************************************/

  ADC_RegularChannelConfig(ADC3, ADC_Channel_0, 1, ADC_SampleTime_480Cycles);

  ADC_RegularChannelConfig(ADC3, ADC_Channel_1, 2, ADC_SampleTime_480Cycles);

  ADC_RegularChannelConfig(ADC3, ADC_Channel_2, 3, ADC_SampleTime_480Cycles);

  ADC_RegularChannelConfig(ADC3, ADC_Channel_3, 4, ADC_SampleTime_480Cycles);

 /* Enable DMA request after last transfer (Single-ADC mode) */

  ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);

  /* Enable ADC3 DMA */

  ADC_DMACmd(ADC3, ENABLE);

  /* Enable ADC3 */

  ADC_Cmd(ADC3, ENABLE);

}

Posted on August 11, 2014 at 05:31

No, this is not an area I have invested any time in. I'd recommend you review the examples in the firmware library, and understand the relationship between the time base and the compare registers, and how you want to modulate the signal.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..