#include "MDRFxx_SFR.h"
#include "main.h"
#include "Pwm.h"
#include "Motor.h"


//void PWM_SetBreak (void)
//{
//	MPWMCONT = SWAP | ActiveLow<<2 | ForceLow;
//	SYNC = 0x55;
//}

void PWM_SetBreakForce (void)
{
	MPWMCONT = SWAP | ForceHi<<2 | ForceLow;
	SYNC = 0x55;
}

//void PWM_Duty (unsigned short PwmDuty)
//{
//	SFR_PAGE = 1; MPWMDATA = PwmDuty; SYNC = 0x55;// PWM Duty U
//	SFR_PAGE = 2; MPWMDATA = PwmDuty; SYNC = 0x55;// PWM Duty V
//	SFR_PAGE = 3; MPWMDATA = PwmDuty; SYNC = 0x55;// PWM Duty W
//}

void PWM_SetAllOff (void)
{
	MPWMCONT = SWAP | 0x00;
	SYNC = 0x55;
}

void PWM_SetActive (void)
{
	MPWMCONT = SWAP | ActiveLow<<2 | ActiveHi;
	SYNC = 0x55;
}

void PWM_Init (void)
{
	SFR_PAGE = 0;
	MPWMDATA = MPWMDATA_REGS;
	SYNC = 0x55;
	MPWMINV = MPWMINV_REGS;
	SYNC = 0x55;
	MPWMDB = MPWMDB_REGS;
	SYNC = 0x55;
	PWM_SetAllOff();
}
