cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Signals

smvhauge
Associate II
Posted on March 02, 2014 at 19:38

Hi. I'm currently in a group who are building an ROV and using the stm32f100rb to controll 7 rc motors. The issue I'm having is when outputting a pwm signal to a osciloscop I get a very rough resolution. The signal is supposed to be between 1 ms and 2 ms, and I would like to atleast be able to set the width to 1,00 to 2,00 ms (100 steps). When I alter the width now, i only get 1,0ms 1,2ms, 1,4ms, 1,6ms, 1,8ms and 2,0 ms. It rounds of to the closest one. Anybody knows what might be the problem?

#stm32 #pwm #discovery #output
6 REPLIES 6
Posted on March 03, 2014 at 00:54

As I have to guess what you've coded I might presume your prescaler is too large.

I've posted servo code in the past

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Servo%20control%20using%20STM32VLDiscovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000491D59B8574F8049B5DFA3E8B21CBA51&currentviews=2039]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32VLDiscovery%2FServo%20control%20using%20STM32VLDiscovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000491D59B8574F8049B5DFA3E8B21CBA51¤tviews=2039
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
smvhauge
Associate II
Posted on March 03, 2014 at 10:58

Thanx for the fast answer. Sorry, forgot to post the code. Here's what I've got:

int main(void){

initialization_Timers();

PWM_Truster_1_width(1000);

while(1){

}

}

void initialization_Timers (void){

RCC_Configuration(); //(Must be before GPIO_timer_config!)

GPIO_timer_config();

TIM_periode= 20000-1;

PrescalerValue =24-1;

/* Time base configuration */

TIM_TimeBaseStructure.TIM_Period = TIM_periode;

TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

//initialization of timer 2

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

//initialization of timer 3

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

/* TIM2 enable counter */

TIM_Cmd(TIM2, ENABLE);

/* TIM3 enable counter */

TIM_Cmd(TIM3, ENABLE);

/*set's the initial values for the PWM-outputs

PWM_Truster_1_width(1500);

}

void PWM_Truster_1_width(uint16_t width){

width_1=width;

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

TIM_OCInitStructure.TIM_Pulse =width;//width;//endre her

TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

TIM_OC1Init(TIM2, &TIM_OCInitStructure);

TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);

}

Can you spot whats wrong?
Posted on March 03, 2014 at 15:38

If you are running the the buses at 24 MHz, the period should be 20 ms (50 Hz) confirm that.

The width should be programmable with 1 us granularity, as the timer is clocking at 1 MHz.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
smvhauge
Associate II
Posted on March 03, 2014 at 17:45

Yes, the periode time is 20 ms, and I also get a pulse between 1 and 2 ms, but its a realy course resolution as I'm only able to change it by 0,2 ms either way. 

Posted on March 03, 2014 at 19:44

You should be able to change the pulse width in 1 micro-second units, if you can only resolved 0.2 ms (200 us) then I'd have to question how you are measuring the signal.

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

Thanx for all your help. Just found out the scope was calibrated wrong. So, sorry for bothering you.