Pierre rouaze
/
fastpwmexample
example for using fast pwm
Example for the use of fast pwm on an stm nucleo F302R8.
main.cpp
- Committer:
- rouaze
- Date:
- 2016-03-01
- Revision:
- 0:e89048c4d596
- Child:
- 1:1ac1f46ae264
- Child:
- 2:82d62dda5cc9
File content as of revision 0:e89048c4d596:
#include "mbed.h" #include "FastPWM.h" //setting pwm outputs FastPWM buck(D11,1); FastPWM boost(D10,1); //seting analog input AnalogIn analog_value(A0); //setup serial coms Serial pc(USBTX, USBRX); //setup ticker Ticker toggle_sample_ticker; //setup gobal variables int count=0; int SampleSum=0; float sample[8]; //setup interrupt sample function void sampling() { if(count<8) { count=count+1; sample[count]=(analog_value.read()); SampleSum=(sample[0]+sample[1]+sample[2]+sample[3]+sample[4]+sample[5]+sample[6]+sample[7]); } else count=0; } //setup pwm function void buckpwm(int pwm){ if (pwm <=100) { buck.pulsewidth_ticks( pwm ); } } int main() { //setup pwm uint32_t period_ticks=720; buck.prescaler(1); boost.prescaler(1); // define period of pwm... buck.period_ticks (period_ticks); boost.period_ticks (period_ticks); //define duty cycle buckpwm(1); boost.pulsewidth_us(3); //boostpwm(10); while(1) { toggle_sample_ticker.attach(&sampling, 0.0000011); // will cal mycode every 1/8000 second pc.printf("\t%i\n",SampleSum); } }