This program manually generates a PWM signal. For educational use.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 void countDirection(int);
00004 DigitalOut steering_pwm(PTE20);
00005 int count = 0;
00006 int ref = 120e3;
00007 int countDir = 0;
00008 
00009 /*void countDirection(int)
00010 {
00011     if (countDir = 0) {
00012         count++;
00013     } else (countDir = 1) {
00014         count--;
00015     }
00016 }*/
00017 
00018 int main()
00019 {
00020     while(1) {
00021         if (count == 1) {
00022             countDir = 0;
00023         }   else if(count == 240e3){
00024             countDir = 1;
00025         }
00026 
00027         if (countDir == 0) {
00028             count+=1;
00029         } else if (countDir == 1) {
00030             count+=-1;
00031         }
00032 
00033         if (count <= ref) {
00034             steering_pwm = 1;
00035         } else {
00036             steering_pwm = 0;
00037         }
00038     }
00039 }