<root>
<document schema='101' license='1,Monie Jacobsen,A663VK' title='' description='' target='AVR.ATMEGA.Arduino Mega 2560 R3' >
	<config data='' clkspd='16000000' simspd='1' usewdt='0' constif='0' />
	<plugins >
		<dll_dbg_icd enabled='0' >
			<data name='debug' value='1' />
			<data name='userpins' value='0' />
			<data name='speed' value='0' />
			<data name='usev9' value='0' />
			<data name='breaks' value='8' />
			<data name='stacks' value='8' />
			<data name='clkport' value='1' />
			<data name='clkbit' value='6' />
			<data name='dataport' value='1' />
			<data name='databit' value='7' />
			<data name='ghostype' value='0' />
			<data name='monitor' value='1' />
			<data name='ictloop' value='0' />
			<data name='ictrate' value='20000' />
			<data name='ictmask' value='0' />
			<data name='anlpres' value='255' />
			<data name='digmask1' value='-1' />
			<data name='digmask2' value='-1' />
		</dll_dbg_icd>
		<dll_models enabled='1' />
		<dll_upgrader enabled='1' />
		<dll_webhelp enabled='1' />
	</plugins>
	<supplement use='0' head='' body='' />
	<debug >
		<watch expr='Amp' />
		<watch expr='Request_Current' />
	</debug>
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='79d4ac39-adac-4823-a83e-04bdf375e21e' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='0' iconpath='' />
		<component class_type='root' codename='panel' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='0' poslock='0' >
			<resources />
			<properties />
			<values />
			<events />
			<apis />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='ACS7xxTest' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='5' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='false' type='b1' description='' isconst='1' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Request_Current' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='20' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Amp' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='5' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isinit='1' usrinit='1' setinit='1' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='Request_Current' description='' >
						<return name='Return' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</return>
						<command class_type='native' title='C Code' ccode='//************************************************************************************
//**  
//**  Source name:   E:\FlowCode V7 Projekter\Arduino Mega 2560 R3\ACS7xx\ACS7xx.fcfx
//**  Title:         
//**  Description:   
//**  Device:        AVR.ATMEGA.ATMEGA2560
//**  
//**  Generated by:  Flowcode v6.1.3.2
//**  Date:          Wednesday, August 03, 2016 11:12:21
//**  Users:         1
//**  Registered to: Monie Jacobsen
//**  Licence key:   XXXXXXX
//**  
//**  
//**  http://www.matrixtsl.com
//**  
//************************************************************************************


#define MX_AVR #define MX_CAL_AVR #define MX_CLK_SPEED 16000000 #define FCP_NULL Unconnected_Port #define MX_UART_ID
#define MX_UART_UCSRC

#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
#include &lt;avr\io.h&gt;
#include &lt;avr\interrupt.h&gt;
#include &lt;avr\eeprom.h&gt;
#include &lt;avr\wdt.h&gt;


/*========================================================================*\
   Use :Include the type definitions
\*========================================================================*/
#include &quot;E:\Flowcode 6\CAL\internals.c&quot;



/*========================================================================*\
   Use :panel
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define FCVsz_AMP 5
#define FCV_FALSE (0)
#define FCV_TRUE (1)
MX_GLOBAL MX_CHAR FCV_AMP[FCVsz_AMP];


/*========================================================================*\
   Use :fcdhelper
       :Variable declarations
       :Macro function declarations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define ADC_1_MX_ADC_ACTIME 40
#define MX_ADC_REF 
#define ADC_1_MX_ADC_VREFVOL 500
#define MX_ADC_CHANNEL_0 
#define MX_ADC_TYPE_10 
#define ADC_1_MX_ADC_VREFOP 0
#define ADC_1_MX_ADC_CONVSP 3
#define MX_ADC_BITS_10 
#define ADC_1_MX_ADC_CHANNEL 0

#define FCV_0aae1_cal_adc__FALSE (0)
#define FCV_0aae1_cal_adc__TRUE (1)

void FC_CAL_ADC_Disable();
void FC_CAL_ADC_Enable(MX_UINT8 FCL_CHANNEL, MX_UINT8 FCL_CONV_SPEED, MX_UINT8 FCL_VREF, MX_UINT8 FCL_T_CHARGE);
MX_UINT16 FC_CAL_ADC_Sample(MX_UINT8 FCL_SAMPLE_MODE);

/*========================================================================*\
   Use :adc_base
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
MX_UINT16 FCD_08f41_adc_base__RawSampleInt();
MX_UINT8 FCD_08f41_adc_base__RawAverageByte(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS);
void FCD_08f41_adc_base__GetString(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL);
MX_UINT8 FCD_08f41_adc_base__GetAverageByte(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS);
MX_SINT16 FCD_08f41_adc_base__RawAverageInt(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS);
MX_UINT16 FCD_08f41_adc_base__GetAverageInt(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS);
MX_FLOAT FCD_08f41_adc_base__GetVoltage();
void FCD_08f41_adc_base__RawEnable();
MX_UINT8 FCD_08f41_adc_base__RawSampleByte();
MX_UINT16 FCD_08f41_adc_base__GetInt();
void FCD_08f41_adc_base__RawDisable();
MX_UINT8 FCD_08f41_adc_base__GetByte();

/*========================================================================*\
   Use :slider_plastic1
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define FCD_0d101_slider_plastic1__RawSampleInt FCD_08f41_adc_base__RawSampleInt
#define FCD_0d101_slider_plastic1__RawAverageByte FCD_08f41_adc_base__RawAverageByte
#define FCD_0d101_slider_plastic1__GetString FCD_08f41_adc_base__GetString
#define FCD_0d101_slider_plastic1__GetAverageByte FCD_08f41_adc_base__GetAverageByte
#define FCD_0d101_slider_plastic1__RawAverageInt FCD_08f41_adc_base__RawAverageInt
#define FCD_0d101_slider_plastic1__GetAverageInt FCD_08f41_adc_base__GetAverageInt
#define FCD_0d101_slider_plastic1__GetVoltage FCD_08f41_adc_base__GetVoltage
#define FCD_0d101_slider_plastic1__RawEnable FCD_08f41_adc_base__RawEnable
#define FCD_0d101_slider_plastic1__RawSampleByte FCD_08f41_adc_base__RawSampleByte
#define FCD_0d101_slider_plastic1__GetInt FCD_08f41_adc_base__GetInt
#define FCD_0d101_slider_plastic1__RawDisable FCD_08f41_adc_base__RawDisable
#define FCD_0d101_slider_plastic1__GetByte FCD_08f41_adc_base__GetByte

/*========================================================================*\
   Use :ACS7xx1
       :Variable declarations
       :Macro function declarations
\*========================================================================*/
#define FCVsz_084c1_ACS7xx1__CURRENTGLOBAL 20
#define FCVsz_084c1_ACS7xx1__DEVICE_TYPE_STR 20
MX_GLOBAL MX_UINT8 FCV_084c1_ACS7xx1__DEVICE_TYPE;
MX_GLOBAL MX_CHAR FCV_084c1_ACS7xx1__CURRENTGLOBAL[FCVsz_084c1_ACS7xx1__CURRENTGLOBAL];
MX_GLOBAL MX_CHAR FCV_084c1_ACS7xx1__DEVICE_TYPE_STR[FCVsz_084c1_ACS7xx1__DEVICE_TYPE_STR];

void FCD_084c1_ACS7xx1__ReadCurrent_ACS712(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL);
void FCD_084c1_ACS7xx1__Request_Current(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL);
void FCD_084c1_ACS7xx1__ReadCurrent_ACS758(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL);
void FCD_084c1_ACS7xx1__ReadCurrent_ACS761(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL);

/*========================================================================*\
   Use :Include the chip adaption layer
\*========================================================================*/
#include &quot;E:\Flowcode 6\CAL\includes.c&quot;


/*========================================================================*\
   Use :fcdhelper
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :cal_adc
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :adc_base
       :Macro implementations
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Background call to read the ADC at full bit depth        :Call Enable() first
       :
       :Returns : MX_UINT16
\*=----------------------------------------------------------------------=*/
MX_UINT16 FCD_08f41_adc_base__RawSampleInt()
{
	//Lokal variabel definitation
	MX_UINT16 FCR_RETVAL;


	FCR_RETVAL = FC_CAL_ADC_Sample(1);

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Background call to read the ADC as a byte average sample over time        :Call Enable() before this
       :
       :Parametre for macro RawAverageByte:
       :  NumSamples : MX_UINT8
       :  DelayUs : Number of micro seconds in between taking each sample
       :
       :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_08f41_adc_base__RawAverageByte(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS)
{
	//Lokal variabel definitation
	MX_UINT16 FCL_AVERAGE = (0x0);
	MX_UINT8 FCL_COUNT = (0x0);
	MX_UINT8 FCR_RETVAL;


	if (FCL_DELAYUS &gt; 0)
	{

		while (FCL_COUNT &lt; FCL_NUMSAMPLES)
		{

			FCL_AVERAGE = FCL_AVERAGE + FC_CAL_ADC_Sample(0);
			FCL_COUNT = FCL_COUNT + 1;

			FCI_DELAYBYTE_US(FCL_DELAYUS);


		}

	} else {

		while (FCL_COUNT &lt; FCL_NUMSAMPLES)
		{

			FCL_AVERAGE = FCL_AVERAGE + FC_CAL_ADC_Sample(0);
			FCL_COUNT = FCL_COUNT + 1;


		}

	}

	FCR_RETVAL = FCL_AVERAGE / FCL_COUNT;

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Reads the ADC as a direct voltage and returns as as tring
       :
       :Returns : MX_CHAR
\*=----------------------------------------------------------------------=*/
void FCD_08f41_adc_base__GetString(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL)
{
	//Lokal variabel definitation
	MX_FLOAT FCL_SAMPLE;


	FCL_SAMPLE = FCD_08f41_adc_base__GetVoltage();

	FCI_FLOAT_TO_STRING(FCL_SAMPLE, FCV_PRECISION, FCR_RETVAL,20);

}

/*=----------------------------------------------------------------------=*\
   Use :Function call to read the ADC as a byte average sample over time
       :
       :Parametre for macro GetAverageByte:
       :  NumSamples : MX_UINT8
       :  DelayUs : Number of micro seconds in between taking each sample
       :
       :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_08f41_adc_base__GetAverageByte(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS)
{
	//Lokal variabel definitation
	MX_UINT8 FCR_RETVAL;


	FC_CAL_ADC_Enable(0, 3, 0, 40);

	FCR_RETVAL = FCD_08f41_adc_base__RawAverageByte(FCL_NUMSAMPLES, FCL_DELAYUS);

	FC_CAL_ADC_Disable();

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Background call to read the ADC as a full width average sample over time        :Call Enable() before this
       :
       :Parametre for macro RawAverageInt:
       :  NumSamples : MX_UINT8
       :  DelayUs : MX_UINT8
       :
       :Returns : MX_SINT16
\*=----------------------------------------------------------------------=*/
MX_SINT16 FCD_08f41_adc_base__RawAverageInt(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS)
{
	//Lokal variabel definitation
	MX_UINT32 FCL_AVERAGE = (0x0);
	MX_UINT8 FCL_COUNT = (0x0);
	MX_SINT16 FCR_RETVAL;


	if (FCL_DELAYUS &gt; 0)
	{

		while (FCL_COUNT &lt; FCL_NUMSAMPLES)
		{

			FCL_AVERAGE = FCL_AVERAGE + FC_CAL_ADC_Sample(1);
			FCL_COUNT = FCL_COUNT + 1;

			FCI_DELAYBYTE_US(FCL_DELAYUS);


		}

	} else {

		while (FCL_COUNT &lt; FCL_NUMSAMPLES)
		{

			FCL_AVERAGE = FCL_AVERAGE + FC_CAL_ADC_Sample(1);
			FCL_COUNT = FCL_COUNT + 1;


		}

	}

	FCR_RETVAL = FCL_AVERAGE / FCL_COUNT;

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Function call to read the ADC as a full width average sample over time
       :
       :Parametre for macro GetAverageInt:
       :  NumSamples : MX_UINT8
       :  DelayUs : Number of micro seconds in between taking each sample
       :
       :Returns : MX_UINT16
\*=----------------------------------------------------------------------=*/
MX_UINT16 FCD_08f41_adc_base__GetAverageInt(MX_UINT8 FCL_NUMSAMPLES, MX_UINT8 FCL_DELAYUS)
{
	//Lokal variabel definitation
	MX_UINT16 FCR_RETVAL;


	FC_CAL_ADC_Enable(0, 3, 0, 40);

	FCR_RETVAL = FCD_08f41_adc_base__RawAverageInt(FCL_NUMSAMPLES, FCL_DELAYUS);

	FC_CAL_ADC_Disable();

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Reads the ADC as a direct voltage
       :
       :Returns : MX_FLOAT
\*=----------------------------------------------------------------------=*/
MX_FLOAT FCD_08f41_adc_base__GetVoltage()
{
	//Lokal variabel definitation
	MX_UINT16 FCL_SAMPLE;
	MX_FLOAT FCR_RETVAL;


	FC_CAL_ADC_Enable(0, 3, 0, 40);

	FCL_SAMPLE = FC_CAL_ADC_Sample(1);

	FCR_RETVAL = flt_mul(flt_fromi(FCL_SAMPLE), 0.004883);

	FC_CAL_ADC_Disable();

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Enables and configures the ADC channel to be an analogue input.        :Only one ADC channel can be enabled at a time. Any RAW functions will reference the last enabled channel only.
\*=----------------------------------------------------------------------=*/
void FCD_08f41_adc_base__RawEnable()
{

	FC_CAL_ADC_Enable(0, 3, 0, 40);

}

/*=----------------------------------------------------------------------=*\
   Use :Background call to read the ADC as a byte        :Call Enable() before this
       :
       :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_08f41_adc_base__RawSampleByte()
{
	//Lokal variabel definitation
	MX_UINT8 FCR_RETVAL;


	FCR_RETVAL = FC_CAL_ADC_Sample(0);

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Blocking call to read the ADC at full bit depth
       :
       :Returns : MX_UINT16
\*=----------------------------------------------------------------------=*/
MX_UINT16 FCD_08f41_adc_base__GetInt()
{
	//Lokal variabel definitation
	MX_UINT16 FCR_RETVAL;


	FC_CAL_ADC_Enable(0, 3, 0, 40);

	FCR_RETVAL = FC_CAL_ADC_Sample(1);

	FC_CAL_ADC_Disable();

	return (FCR_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Disables the previously enabled ADC channel and converts back to digital mode.
\*=----------------------------------------------------------------------=*/
void FCD_08f41_adc_base__RawDisable()
{

	FC_CAL_ADC_Disable();

}

/*=----------------------------------------------------------------------=*\
   Use :Blocking call to read the ADC as a byte
       :
       :Returns : MX_UINT8
\*=----------------------------------------------------------------------=*/
MX_UINT8 FCD_08f41_adc_base__GetByte()
{
	//Lokal variabel definitation
	MX_UINT8 FCR_RETVAL;


	FC_CAL_ADC_Enable(0, 3, 0, 40);

	FCR_RETVAL = FC_CAL_ADC_Sample(0);

	FC_CAL_ADC_Disable();

	return (FCR_RETVAL);

}


/*========================================================================*\
   Use :slider_plastic1
       :Macro implementations
\*========================================================================*/

/*========================================================================*\
   Use :ACS7xx1
       :Macro implementations
\*========================================================================*/
/*=----------------------------------------------------------------------=*\
   Use :Returns : MX_CHAR
\*=----------------------------------------------------------------------=*/
void FCD_084c1_ACS7xx1__ReadCurrent_ACS712(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL)
{
	//Lokal variabel definitation
	#define FCL_VOLTAGE_MULTIPLIER (0.0048874998465180397)
	#define FCL_SENSITIVITY_ACS712 (0.18500000238418579)
	MX_SINT16 FCL_CURRENTRAW;
	MX_SINT16 FCL_CURRENT_DIF;
	MX_FLOAT FCL_CURRENT_DIF_FLT;
	#define FCLsz_CURRENT_STR 20
	MX_CHAR FCL_CURRENT_STR[FCLsz_CURRENT_STR];
	#define FCLsz_CURRENT_L 20
	MX_CHAR FCL_CURRENT_L[FCLsz_CURRENT_L];
	#define FCLsz_CURRENT_H 20
	MX_CHAR FCL_CURRENT_H[FCLsz_CURRENT_H];
	MX_SINT16 FCL_ZERO_CURRENT;


	FCD_0d101_slider_plastic1__RawEnable();

	FCL_CURRENTRAW = FCD_0d101_slider_plastic1__RawAverageInt(128, 21);

	if (FCL_CURRENTRAW &gt; 702)
	{

		FCL_CURRENTRAW = 702;

	} else {

		if (FCL_CURRENTRAW &lt; 322)
		{

			FCL_CURRENTRAW = 322;

		// } else {

		}

	}

	if (FCL_CURRENTRAW &gt; 512)
	{

		FCL_CURRENT_DIF_FLT = flt_fromi(FCL_CURRENTRAW - 512);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS712);

		FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
		FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
		FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
		FCI_SHEAD(&quot;+&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

	} else {

		FCL_CURRENT_DIF_FLT = flt_fromi(512 - FCL_CURRENTRAW);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS712);

		FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
		FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
		FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
		FCI_SHEAD(&quot;-&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
		FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

	}

	FCI_SCOPY(FCL_CURRENT_STR,FCLsz_CURRENT_STR, FCV_084c1_ACS7xx1__CURRENTGLOBAL,FCVsz_084c1_ACS7xx1__CURRENTGLOBAL);

	//Lokal variabel definitation
	#undef FCL_VOLTAGE_MULTIPLIER
	#undef FCL_SENSITIVITY_ACS712
	#undef FCLsz_CURRENT_STR
	#undef FCLsz_CURRENT_L
	#undef FCLsz_CURRENT_H
}

/*=----------------------------------------------------------------------=*\
   Use :Returns : MX_CHAR
\*=----------------------------------------------------------------------=*/
void FCD_084c1_ACS7xx1__Request_Current(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL)
{
	//Lokal variabel definitation



	FCI_RIGHTSTRING(&quot;058&quot;, 4, 2, FCV_084c1_ACS7xx1__DEVICE_TYPE_STR,20);
	FCV_084c1_ACS7xx1__DEVICE_TYPE = FCI_STRING_TO_INT(FCV_084c1_ACS7xx1__DEVICE_TYPE_STR, FCVsz_084c1_ACS7xx1__DEVICE_TYPE_STR);

	switch (FCV_084c1_ACS7xx1__DEVICE_TYPE)
	{
		case 12:
		{
			FCD_084c1_ACS7xx1__ReadCurrent_ACS712(FCI_TMP_STR,20 );

			break;
		}
		case 58:
		{
			FCD_084c1_ACS7xx1__ReadCurrent_ACS758(FCI_TMP_STR,20 );

			break;
		}
		case 61:
		{
			FCD_084c1_ACS7xx1__ReadCurrent_ACS761(FCI_TMP_STR,20 );

			break;
		}
		// default:

	}

	FCI_SCOPY(FCV_084c1_ACS7xx1__CURRENTGLOBAL,FCVsz_084c1_ACS7xx1__CURRENTGLOBAL, FCR_RETVAL,FCRsz_RETVAL);

}

/*=----------------------------------------------------------------------=*\
   Use :Returns : MX_CHAR
\*=----------------------------------------------------------------------=*/
void FCD_084c1_ACS7xx1__ReadCurrent_ACS758(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL)
{
	//Lokal variabel definitation
	#define FCL_VOLTAGE_MULTIPLIER (0.0048874998465180397)
	#define FCL_SENSITIVITY_ACS758 (0.039999999105930328)
	MX_SINT16 FCL_CURRENTRAW;
	MX_SINT16 FCL_CURRENT_DIF;
	MX_FLOAT FCL_CURRENT_DIF_FLT;
	#define FCLsz_CURRENT_STR 20
	MX_CHAR FCL_CURRENT_STR[FCLsz_CURRENT_STR];
	#define FCLsz_CURRENT_L 20
	MX_CHAR FCL_CURRENT_L[FCLsz_CURRENT_L];
	#define FCLsz_CURRENT_H 20
	MX_CHAR FCL_CURRENT_H[FCLsz_CURRENT_H];
	MX_SINT16 FCL_ZERO_CURRENT;


	FCD_0d101_slider_plastic1__RawEnable();

	FCL_CURRENTRAW = FCD_0d101_slider_plastic1__RawAverageInt(128, 21);

	if (FCL_CURRENTRAW &gt; 925)
	{

		FCL_CURRENTRAW = 925;

	} else {

		if (FCL_CURRENTRAW &lt; 100)
		{

			FCL_CURRENTRAW = 100;

		// } else {

		}

	}

	if (FCL_CURRENTRAW &gt; 512)
	{

		FCL_CURRENT_DIF_FLT = flt_fromi(FCL_CURRENTRAW - 512);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS758);

		if (FCL_CURRENTRAW &gt; 593)
		{

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 2, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;+&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

		} else {

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;+&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot; &quot;,2, FCL_CURRENT_STR,20);

		}

	} else {

		FCL_CURRENT_DIF_FLT = flt_fromi(512 - FCL_CURRENTRAW);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS758);

		if (FCL_CURRENTRAW &lt; 430)
		{

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 2, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;-&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

		} else {

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;-&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot; &quot;,2, FCL_CURRENT_STR,20);

		}

	}

	FCI_SCOPY(FCL_CURRENT_STR,FCLsz_CURRENT_STR, FCV_084c1_ACS7xx1__CURRENTGLOBAL,FCVsz_084c1_ACS7xx1__CURRENTGLOBAL);

	//Lokal variabel definitation
	#undef FCL_VOLTAGE_MULTIPLIER
	#undef FCL_SENSITIVITY_ACS758
	#undef FCLsz_CURRENT_STR
	#undef FCLsz_CURRENT_L
	#undef FCLsz_CURRENT_H
}

/*=----------------------------------------------------------------------=*\
   Use :Returns : MX_CHAR
\*=----------------------------------------------------------------------=*/
void FCD_084c1_ACS7xx1__ReadCurrent_ACS761(MX_CHAR *FCR_RETVAL, MX_UINT16 FCRsz_RETVAL)
{
	//Lokal variabel definitation
	#define FCL_VOLTAGE_MULTIPLIER (0.0048874998465180397)
	#define FCL_SENSITIVITY_ACS761 (0.064999997615814209)
	MX_SINT16 FCL_CURRENTRAW;
	MX_SINT16 FCL_CURRENT_DIF;
	MX_FLOAT FCL_CURRENT_DIF_FLT;
	#define FCLsz_CURRENT_STR 20
	MX_CHAR FCL_CURRENT_STR[FCLsz_CURRENT_STR];
	#define FCLsz_CURRENT_L 20
	MX_CHAR FCL_CURRENT_L[FCLsz_CURRENT_L];
	#define FCLsz_CURRENT_H 20
	MX_CHAR FCL_CURRENT_H[FCLsz_CURRENT_H];
	MX_SINT16 FCL_ZERO_CURRENT;


	FCD_0d101_slider_plastic1__RawEnable();

	FCL_CURRENTRAW = FCD_0d101_slider_plastic1__RawAverageInt(128, 21);

	if (FCL_CURRENTRAW &gt; 780)
	{

		FCL_CURRENTRAW = 780;

	} else {

		if (FCL_CURRENTRAW &lt; 244)
		{

			FCL_CURRENTRAW = 244;

		// } else {

		}

	}

	if (FCL_CURRENTRAW &gt; 512)
	{

		FCL_CURRENT_DIF_FLT = flt_fromi(FCL_CURRENTRAW - 512);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS761);

		if (FCL_CURRENTRAW &gt; 644)
		{

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 2, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;+&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

		} else {

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;+&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot; &quot;,2, FCL_CURRENT_STR,20);

		}

	} else {

		FCL_CURRENT_DIF_FLT = flt_fromi(512 - FCL_CURRENTRAW);
		FCL_CURRENT_DIF_FLT = flt_mul(FCL_CURRENT_DIF_FLT, FCL_VOLTAGE_MULTIPLIER);
		FCL_CURRENT_DIF_FLT = flt_div(FCL_CURRENT_DIF_FLT, FCL_SENSITIVITY_ACS761);

		if (FCL_CURRENTRAW &lt; 380)
		{

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 2, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;-&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCL_CURRENT_STR,20);

		} else {

			FCI_FLOAT_TO_STRING(FCL_CURRENT_DIF_FLT, FCV_PRECISION, FCL_CURRENT_STR,20);
			FCI_LEFTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 1, FCL_CURRENT_H,20);
			FCI_RIGHTSTRING(FCL_CURRENT_STR, FCLsz_CURRENT_STR, 3, FCL_CURRENT_L,20);
			FCI_SHEAD(&quot;-&quot;,2, FCL_CURRENT_H,FCLsz_CURRENT_H, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;,&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, FCL_CURRENT_L,FCLsz_CURRENT_L, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot;A&quot;,2, FCI_TMP_STR,20);
			FCI_SHEAD(FCI_TMP_STR,20, &quot; &quot;,2, FCL_CURRENT_STR,20);

		}

	}

	FCI_SCOPY(FCL_CURRENT_STR,FCLsz_CURRENT_STR, FCV_084c1_ACS7xx1__CURRENTGLOBAL,FCVsz_084c1_ACS7xx1__CURRENTGLOBAL);

	//Lokal variabel definitation
	#undef FCL_VOLTAGE_MULTIPLIER
	#undef FCL_SENSITIVITY_ACS761
	#undef FCLsz_CURRENT_STR
	#undef FCLsz_CURRENT_L
	#undef FCLsz_CURRENT_H
}


/*========================================================================*\
   Use :panel
       :Macro implementations
\*========================================================================*/


/*========================================================================*\
   Use :Main
\*========================================================================*/
int main()
{ 	MCUCR=0x00;
	MCUSR=0x00;
	wdt_disable();
 	EIMSK=0x00;

 	// løkke
	// løkke: While 1
	while (1)
	{

		// Kald Komponent Macro
		// Kald Komponent Macro: Amp=ACS7xx1::Request_Current()
		FCD_084c1_ACS7xx1__Request_Current(FCV_AMP,5 );


	}

	mainendloop: goto mainendloop;
}

 
/*========================================================================*\
   Use :Interrupt
\*========================================================================*/
  

' language='C' />
						<command class_type='calculation' title='Beregning' >
							<exp exp='.Return = Request_Current' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Call Component Macro' component='lcd_I2C1' macro='Start' />
						<command class_type='loop' title='løkke' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='Request_Current' >
									<return exp='Amp' />
								</command>
								<command class_type='call' title='Kald Komponent Macro' disable='1' component='ACS7xx1' macro='Request_Current' >
									<return exp='Amp' />
								</command>
								<command class_type='call' title='Call Component Macro' component='lcd_I2C1' macro='Cursor' >
									<argument exp='0' />
									<argument exp='0' />
								</command>
								<command class_type='call' title='AMP' component='lcd_I2C1' macro='PrintString' >
									<argument exp='Amp' />
								</command>
								<command class_type='call' title='Kald Komponent Macro' component='lcd_I2C1' macro='PrintString' >
									<argument exp='&quot; A&quot;' />
								</command>
								<command class_type='delay' title='forskydning' exp='100' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='0975aa2f-6601-4181-9676-7a8b45184e3c' vmin='1' vmaj='1' codename='ACS7xx1' x='0' y='-58' z='5' xsz='50' ysz='67.5' zsz='10' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='1' poslock='0' >
				<resources />
				<properties />
				<values >
					<value target='DeviceType' data='058' />
					<value target='channel' data='2' />
					<value target='FAULT_0_61' data='' />
					<value target='PGOOD_0_61' data='' />
					<value target='PGOOD_61' data='' />
					<value target='vrefvol' data='500' />
					<value target='vrefop' data='000' />
					<value target='convspd' data='003' />
					<value target='actime' data='40' />
					<value target='bits' data='10' />
					<value target='bitmul' data='0.004883' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='bcd6a955-12c6-4ed4-a22f-f16eb62e0762' vmin='1' vmaj='1' codename='lcd_I2C1' x='0' y='30' z='3.575' xsz='2.5' ysz='2.75482' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='1' poslock='0' >
				<resources />
				<properties />
				<values >
					<value target='Channel' data='001' />
					<value target='SDA' data='$PORTD.1' />
					<value target='SCL' data='$PORTD.0' />
					<value target='Address' data='32' />
					<value target='Rows' data='004' />
					<value target='Columns' data='020' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='9737364' img='' style='0' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='25' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAADwUAAKoDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Request_Current' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAADwUAAKoDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
