cancel
Showing results for 
Search instead for 
Did you mean: 

PWM input capture

sbasanth
Associate
Posted on October 27, 2016 at 14:45

Hi ,

We have a requirement to capture the PWM input at Timer2 channel 1.

We are using STM8AF6266 micro.

Requirement:

We have to capture 2 PWM inputs received at Timer2 channel 1.

1) Falling edge 100 - 0 % 200Hz signal in 1sec.

2) Rising edge 0 - 100 % 200Hz signal in 1sec.

Based on this inputs captured We have to update PWM output duty cycle from

 a) 0-100% 200Hz signal in 1 sec (Dimmer ON ) for case 1 input captured

b) 100 - 0% 200Hz signal in 1 sec (Dimmer OFF ) for case 2 input captured.

I have refered to the example code of STM8 and I am not able to meet the requirement  with reference to the sample/example code.

Can anyone help me on this. Please let me know if you have any quires related to it.

Thanks,

1 REPLY 1
Dan Shepherd
Associate
Posted on May 12, 2017 at 01:04

I'm quite new to stm development, but I became interested via flight controllers and noticed that many of them seem to use stm32 based processors.  They use pwm detection and generation for the receiver and also for driving the esc's.  I would suggest looking at the source code for them.  For example in cleanflight which has PWM detection here: 

https://github.com/cleanflight/cleanflight/blob/master/src/main/drivers/rx_pwm.c

 

It might have some dependencies elsewhere in the code but it seems to be quite lightweight and includes lots of useful code that I'm sure will be useful for various projects.

I'm with you, the documentation is rather dry when it comes to stm.  By that I mean lots of datasheets and so on which are detailed and useful but for someone just wanting to program the things they don't provide the friendly getting started tutorials that one gets with other platforms - a real shame because the hardware is excellent.  I guess that is why most opt for raspberry pi python or arduino where lots of the details are hidden.

Good luck