cancel
Showing results for 
Search instead for 
Did you mean: 

Question - How to generate PPM signal with a Timer

Bogdan
Senior
Posted on June 20, 2016 at 15:20

Hello all,

i own a stm32F103c8x device, and since i am a maniac with rc toys, i am working on a ppm generator. Right now i am working with a 16bit timer ( timer3) and for example i put 6 random ppm values, and i expect 6 diferent dutycyles on the same pwm signal... so i configure the time base like this

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCStruct; 
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3 , ENABLE); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;// 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 72-1;// 65000;
TIM_TimeBaseStructure.TIM_Period = 2300;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM3 , &TIM_TimeBaseStructure);
TIM_Cmd(TIM3, ENABLE);
TIM_OCStruct.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCStruct.TIM_Pulse = 0; 
TIM_OC3Init(TIM3, &TIM_OCStruct);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);

and in my main loop i have this : uint16_t pwm_array[6]={1000,1500,1450,1200,1890,1991}; for(int ii=0; ii<6;) { TIM3->CCR3 = pwm_array; ii++; } So on ch3 ( PB0) on timer3 i would expect to have the fist pulse of 1000us, 2nd 1500us and so on... but its not working as expected, i always have 1500us... This is my first time i atempt to generate ppm and i would like to know some advices, Thanks
2 REPLIES 2
Posted on June 20, 2016 at 17:23

One of the methods previously described here for doing PPM is to have the TIM in Toggle mode, and modulate the ARR via a waveform/pattern buffer driven by DMA. ie Table big enough, and looped/circular, describing the high/low widths of the pulse train.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 20, 2016 at 17:25

You can't load the CCRx in a loop like that, you would need to use an IRQ/DMA to sequence through the table.

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