A test program for my interrupt driven PWM motor control

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "i_moto.h"
00003 
00004 //test program for my interrupt driven PWM motor control library
00005 
00006 Serial pc(USBTX, USBRX);
00007 i_moto moto( LED1, 50, 20, 10 );            //in this test the output goes to LED1. Duty cycle = 50 ms, Ramp Up = 20 sec, Ramp Down = 10 sec
00008 
00009 int main() 
00010 {
00011     int z;
00012     
00013     while( 1 )
00014         {
00015         moto.setTargetPower( 100 );             //target power is 100%
00016     
00017         pc.printf( "\r\nTarget Power = %i%%\r\n", moto.getTargetPower() );
00018         pc.printf( "Ramp Up = %i seconds\r\n\n", moto.getRampUp_s() );
00019     
00020         for (z=0; z<25; z++)
00021         {
00022             pc.printf( "Current Power = %i\r\n", moto.getCurrentPower() );
00023             wait( 1 );
00024         }
00025     
00026         moto.setTargetPower( 0 );               //set target power to 0%
00027         pc.printf( "\r\nTarget Power = %i%%\r\n", moto.getTargetPower() );
00028         pc.printf( "Ramp Down = %i secons\r\n\n", moto.getRampDown_s() );
00029     
00030         for (z=0; z<20; z++)
00031         {
00032             pc.printf( "Current Power = %i\r\n", moto.getCurrentPower() );
00033             wait( 1 );
00034         }
00035     }
00036 }