This Library allows you to use any pin on the mbed micro as PWM out. It also allows the user to update the Period and Pulse width in realtime.

main.cpp

Committer:
mr63
Date:
2013-12-08
Revision:
0:9eb94736e774

File content as of revision 0:9eb94736e774:

#include "mbed.h"
#include "PwmOutAny.h"

 Timer t;

 InterruptIn SquareIn (p22);
 DigitalOut status (LED1);



PwmOutAny newPwm (p25,.0001,.50);

void measure_Period()    // this is a test function it looks at a square wave on pin p22 and uses its freq. as the base freq. for the PWM.
{
	static bool first = true;
	static float InputPeriod = .0001;
  static unsigned int count = 0;
	if(first)
	{
		t.reset();
		t.start();
		first = false;
	}
	else
	{
		
		InputPeriod = (InputPeriod + t.read())/2;
		newPwm.Set_Period(InputPeriod);
		status = ! status;
		t.reset();
		t.start();
		count++;
	}
	
}


int main()
	{
	
    SquareIn.rise(&measure_Period);
		
		while(1)
		{
    for(float t=0;t<=1;t+=.01)
			{
				newPwm.Set_PulseWidth(t);
				wait(.1);
			}
		for(float t=1;t>=0;t-=.01)
			{
				newPwm.Set_PulseWidth(t);
				wait(.1);
			}

			
		}
		
	}