<root>
<document schema='101' license='1,Jan Lichtenbelt,C5EM4X' title='' description='' target='PIC.16F.16F1847' >
	<config data='!0,3fff!10,3fff%0,7%3,3%5,1%6,1%7,1%8,1%9,3%b,1%c,1%d,1%10,3%14,1%18,1%19,1%1a,1%1c,1%1d,1' clkspd='19660800' 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='19' />
			<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 />
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='42bd39ea-60d8-4679-8166-85f17c7ed63a' 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='HB0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Vacc_high' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='FV0' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Taquisition_usec' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='FR_internal' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='LB3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</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='LB2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='LB1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='LED_Number' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Timer0_Counter' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='LB0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Vacc_low' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Current' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Tdelay_usec' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Wait_seconds' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Calculations_without_error' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='FVshunt_topside' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='FVshunt_bottomside' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Vlead_low' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='StrTemp' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='5' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Change_seconds' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Voltage_Part' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Vlead_high' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Seconds' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Actual_Led_Number' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='PulseSent' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='HB3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='HB2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='ADC_reading' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isinit='1' usrinit='1' setinit='1' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='FV_terminal' type='f32' description='' isconst='0' isinit='0' usrinit='0.0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='HB1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='Main' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='comment' title='' comment='THIS VERSION HAS ONLY A PART OF THE MAIN MACRO.

Special for 3 ADC conversions in C to reduce the
time to &lt;100 usec

February 2017
Jan Lichtenbelt, Nl' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='native' title='16 MHZ internal oscillator' ccode='OSCCON= 0x78;' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
						<command class_type='comment' title='' comment='1. Initialise, with getting Rshunt, Part of Voltages (2, 4 or 6),
   offtime (10 or 30 sec)' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='loop' title='Endless loop' textarea='36,0,511,300' cmdcolor='3568629' cmdcolor_sec='3568629' type='0' exp='1' >
							<flowline >
								<command class_type='comment' title='' comment='4. Setup ADC&apos;s' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='comment' title='' comment='ADC setup has been moved to INIT macro' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='comment' title='' comment='Tacq the aquisition time (to load the ADC condensor):
Tacq= 2.0 µsec +Tc + 0.05ΔT  
with ΔT the temperature difference compared to 25 oC
and Tc =7.62*10pF*(8k+Rs)
with Rs the external load resistance. 
The optimal Rs is 10k and Tc = 1.4 usec
Other temperatures: increases Tacq with 1 usec/20 oC

The total conversion time is 11.5*Tad
The conversion time for 1 bit Tad 
is for 16 MHz oscillator and ADC clock at Fosc/16: 1 usec
This makes the total conversion time is 11.5 usec.

Ttotal=  Tacq + Tc = 2 + 2 + 11.5 about 16 usec
In the program Tacq is set to 10 usec, so Ttotal is about 22 usec' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='comment' title='' comment='5. Start without shunt and read V0' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='call' title='Read ACD AN1 (V0)' cmdcolor='1975743' cmdcolor_sec='1975743' macro='ADC_AN1' />
								<command class_type='call' title='Caluculate  Battery Voltage without shunt' cmdcolor='1975743' cmdcolor_sec='1975743' macro='ADC_to_Voltage' >
									<return exp='FV0' />
									<argument exp='HB0' />
									<argument exp='LB0' />
								</command>
								<command class_type='comment' title='' comment='6. START WITH SHUNT read Vt, Vh and Vl' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='output' title='Activate gate of MOSFET: set B3 high' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='1' />
								<command class_type='comment' title='' comment='It takes about 10 usec to get gate of 
the MOSFET to become &gt; 4 Volt ' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='delay' title='1. Wait until gate at &gt;4V' cmdcolor='16734207' cmdcolor_sec='16734207' exp='Tdelay_usec' type='0' />
								<command class_type='comment' title='' comment='MOSFET is now on.' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='comment' title='' comment='Wait again 10 usec to load the ADC capacitor (hold time)' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='delay' title='2. Wait ADC aquisition time of 10 usec' cmdcolor='16734207' cmdcolor_sec='16734207' exp='Taquisition_usec' type='0' />
								<command class_type='native' title='Start conversion AN1 (Vt), wait until ready and save data' ccode='ADCON0 = ADCON0 | 0x02;  // start adc conversion. (Set bit1 of ADCON0)
while(test_bit(ADCON0,1)); // wait for end conversion, until bit1 has been reset

FCV_LB1 = ADRESL;
FCV_HB1 = ADRESH;
' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='native' title='Set channel AN0 (Vh) and enable ADC' textarea='43,-13,43,-13' ccode=' ADCON0= 0x01; // reset ADCON0 and select channel AN0 (for ANx ADCON0=x&lt;&lt;2)
               // enable ADC (bit0 of ADCON0)' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='delay' title='Wait ADC acquisition time of 10 usec ' cmdcolor='16734207' cmdcolor_sec='16734207' exp='Taquisition_usec' type='0' />
								<command class_type='native' title='Start conversion AN0 (Vh), wait until ready and save data' ccode='ADCON0 = ADCON0 | 0x02;  // start adc conversion. (Set bit1 of ADCON0)
while(test_bit(ADCON0,1)); // wait for end conversion, until bit1 has been reset

FCV_LB2 = ADRESL;   // safe low byte
FCV_HB2 = ADRESH;  // safe high byte
' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='native' title='Set channel AN6 (Vl) and enable ADC' textarea='36,-7,36,-7' ccode='ADCON0= 0x19;   // reset ADCON0 and select channel AN2 (for ANx ADCON0=x&lt;&lt;2)
                // enable ADC (bit0 of ADCON0)' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='delay' title='Wait ADC aquisition time of 10 usec' cmdcolor='16734207' cmdcolor_sec='16734207' exp='Taquisition_usec' type='0' />
								<command class_type='native' title='Start conversion AN6 (Vl), wait until ready and save data' ccode='ADCON0 = ADCON0 | 0x02;  // start adc conversion. (Set bit1 of ADCON0)
while(test_bit(ADCON0,1)); // wait for end conversion, until bit1 has been reset

FCV_LB3 = ADRESL;
FCV_HB3 = ADRESH;
' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='comment' title='' comment='7. STOP SHUNT     STOP SHUNT     STOP SHUNT     STOP SHUNT     ' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='output' title='Stop shunt: Reset B3 low' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='0' />
								<command class_type='comment' title='' comment='Safety reasons dubble stop' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='output' title='Stop shunt: Reset B3 low' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='0' />
								<command class_type='native' title='Disable ADC&apos;s' ccode='ADCON0=0x00;  // disable ADC&apos;s' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
								<command class_type='comment' title='' comment='8. Transform ADC reading into real voltages' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='calculation' title='(Re)set delay to off time' cmdcolor='16777215' cmdcolor_sec='16777215' >
									<exp exp='Seconds = Wait_seconds // off time' />
									<exp exp='Timer0_Counter = 61 // 61 Hz timer0' />
								</command>
								<command class_type='interrupt' title='Interrupt timer0 with 61 Hz with 16 MHz internal osc' cmdcolor='3610239' cmdcolor_sec='3610239' enable='1' name='TMR0' call='Timer0_Interrupt' >
									<settings timer='1' prescale='256' postscale='-1' rollover='-1' bitcount='-1' trigger='3' maskhi='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' masklo='--------------------------------------------------------------------------------------------------------------------------------------------------------------------------8' >
										<option value='1' />
										<option value='0' />
										<option value='8' />
										<option value='-1' />
									</settings>
								</command>
								<command class_type='call' title='Calculate the V terminal with shunt' cmdcolor='1975743' cmdcolor_sec='1975743' macro='ADC_to_Voltage' >
									<return exp='FV_terminal' />
									<argument exp='HB1' />
									<argument exp='LB1' />
								</command>
								<command class_type='call' title='Calculate the Voltage at the top of the shunt' cmdcolor='1975743' cmdcolor_sec='1975743' macro='ADC_to_Voltage' >
									<return exp='FVshunt_topside' />
									<argument exp='HB2' />
									<argument exp='LB2' />
								</command>
								<command class_type='call' title='Caluclate the voltage at the bottom of the shunt' cmdcolor='1975743' cmdcolor_sec='1975743' macro='ADC_to_Voltage' >
									<return exp='FVshunt_bottomside' />
									<argument exp='HB3' />
									<argument exp='LB3' />
								</command>
								<command class_type='comment' title='' comment='7. Test V &lt; Vmax and current &lt;&gt;0' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
								<command class_type='calculation' title='ADC value for V0 ithout shunt' cmdcolor='16777215' cmdcolor_sec='16777215' >
									<exp exp='ADC_reading = ((HB0 &lt;&lt; 8) + LB0)' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
		</component>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='2105930' 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' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAagQAAKECAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
