2017-03-01 01:06 AM
Hello,
I need a 5-pulse modulation to attack two drivers with a resonant tank to create a sinusoidal.
I have these 5 pulses created with DMA with TIM_CounterMode_Up, if I set them as TIM_CounterMode_CenterAligned3 I get 3 instead of 5. How can i fix this? -5 pulses, but reading only 3 values of the table: 5 pulses reading the 5 values, but i cant fix the square signal to fit only 5 values inside:void TIM3_config(void){
DMA_Configuration(); //DMA1_chanel5
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
GPIOA->CRL = (GPIOA->CRL & 0x00FFFFFF | 0xBB000000); //PA6-7
GPIOA->CRH = (GPIOA->CRH & 0xFFFFFFF0 | 0x0000000B); //PA8 .. TIM1-ch1
//time = (maxfrec * midfrec)/64; //35kHz /256
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // TIM_CounterMode_CenterAligned3 TIM_CounterMode_Up
TIM_TimeBaseStructure.TIM_Period = 312; //time 206,106,312 - Modulation
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned3; // TIM_CounterMode_CenterAligned3 TIM_CounterMode_Up
TIM_TimeBaseStructure.TIM_Period = 10; //TIM3 gated ->> period tim1/10
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
/* Channel 1 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 5; //50% signal
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM3, &TIM_OCInitStructure); //Initializes the TIM3 Channel1
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //invertit
TIM_OC2Init(TIM3, &TIM_OCInitStructure); //Initializes the TIM3 Channel2
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //el possem bé
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //Initializes the TIM1 Channel1
/* Select the Master Slave Mode, configurem TIM1 com master */
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); //TIM2
TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated);
TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0);
/* Master Mode selection */
TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update);
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
//TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
//TIM_SetCounter(TIM1, 10);
TIM_Cmd(TIM1, ENABLE);
TIM_Cmd(TIM3, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
u16 tim3A[5]={50,87,100,87,50};
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_Cmd(DMA1_Channel5, DISABLE);
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_CCR1_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&tim3A; //SRC_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 5;
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_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel5, ENABLE);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
How can I put both onTIM_CounterMode_CenterAligned3, having the 5 values of the table instead 3 Ihave now?
#stm32f103-pwm #center-aligned-pwm #pwm
2017-03-01 02:01 PM
What are those waveforms?
2017-03-02 12:18 AM
Red signal: modulation, based on the tim3A[5] array.
Yellow signal: channel selector, for switching the drivers.The problem is that when I set it as center aligned, instead of reading the 5 data from the array it only reads 3.2017-03-02 02:53 PM
I mean, which STM32Fxx pins did you measure by the oscilloscope?
2017-03-03 12:10 AM
The square signals are on PA6 and PA7 (one inverted).
And the modulation is on PA8