
unit motor
{
	public const uint16 ID = 0;
	
	public link unit INA1 {}
	public link unit INA2 {}
	public link unit INB1 {}
	public link unit INB2 {}
	
	public link unit PWMA {}
	public link unit PWMB {}
	
	int8 valueA;
	int8 valueB;
	int8 tick;
	
	//---------------------
	//[i] var_bool OS_time;
	public uint8 OS_time;
	
	//[i] function_void OS_init;
	public void OS_init()
	{
		INA1.D0_DIR = 1;
		INA1.D0_OUT = 0;
		INA2.D0_DIR = 1;
		INA2.D0_OUT = 0;
		
		INB1.D0_DIR = 1;
		INB1.D0_OUT = 0;
		INB2.D0_DIR = 1;
		INB2.D0_OUT = 0;
		
		valueA = 100;
		valueB = 100;
		tick = 0;
		OS_time = 1;
	}
	
	//---------------------------------------------------
	//[i] function_void OS_run;
	public void OS_run()
	{
		tick % 100;
		bool ResetA = tick == 0;
		bool ResetB = ResetA;
		
		if( tick >= valueA ) {
			PWMA.D0_OUT = 0;
			ResetA = false;
		}
		if( tick >= valueB ) {
			PWMB.D0_OUT = 0;
			ResetB = false;
		}
		tick + 2;
		
		if( ResetA ) {
			PWMA.D0_OUT = 1;
		}
		if( ResetB ) {
			PWMB.D0_OUT = 1;
		}
	}
}
//---------------------------------------------------
OUTA1.D = driver.INA1;
OUTA1.power = driver.valueA;
unit OUTA1
{
	link unit D {}
	link int8 power;
	int8 DT;
}
OUTA2.D = driver.INA2;
OUTA2.power = driver.valueA;
unit OUTA2
{
	link unit D {}
	link int8 power;
	int8 DT;
}
//---------------------------------------------------
OUTB1.D = driver.INB1;
OUTB1.power = driver.valueB;
unit OUTB1
{
	link unit D {}
	link int8 power;
	int8 DT;
}
OUTB2.D = driver.INB2;
OUTB2.power = driver.valueB;
unit OUTB2
{
	link unit D {}
	link int8 power;
	int8 DT;
}

