<root>
<file schema='101' />
<macros >
<macro >
<flowline name='HX711' description='reads data from the HX711 24 bit ADC

Pin B8 = clock out
Pin B9 = data in 
Pin B10 = Auto zero' >
<return name='Return' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
<array size='20' />
</return>
<param name='scale' type='f32' description='scaling factor for load sensor' isconst='0' isinit='0' usrinit='0.0' setinit='' />
<param name='calibrate' type='f32' description='offset for zero of load sensor' isconst='0' isinit='0' usrinit='0.0' setinit='' />
<param name='Average_count' type='u8' description='sets the number of loops for averaging' isconst='0' isinit='0' usrinit='0' setinit='' />
<param name='Average_loop_delay' type='u8' description='sets the delay between each loop [byte]' isconst='0' isinit='0' usrinit='0' setinit='' />
<local name='zero_swx' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
<local name='bit_counter' type='u8' description='bit counter = no of positional bits' isconst='0' isinit='1' usrinit='0' setinit='0' />
<local name='HX_DOUT' type='b1' description='reads the bit value form HX711' isconst='0' isinit='1' usrinit='0' setinit='0' />
<local name='hx771_word_in' type='u8' description='raw data word' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
<array size='24' />
</local>
<local name='hx711_word_out' type='u8' description='raw data word' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
<array size='24' />
</local>
<local name='wgt' type='s32' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
<local name='wgt_ave' type='s32' description='avergae weight store' isconst='0' isinit='1' usrinit='0' setinit='0' />
<command class_type='calculation' title='reset weight value' >
<exp exp='.wgt_ave = 0' />
</command>
<command class_type='loop' title='Averaging loop' type='2' exp='.Average_count' >
<flowline >
<command class_type='calculation' title='reset .wgt for next loop' >
<exp exp='.wgt = 0' />
</command>
<command class_type='delay' title='averae loop delay' exp='.Average_loop_delay' type='1' />
<command class_type='comment' title='' comment='wait until HX711 ready' textarea='12,0,12,0' />
<command class_type='loop' title='check HX711 ready' type='0' forvar='.HX_DOUT = 1' exp='.HX_DOUT = 1' >
<flowline >
<command class_type='input' title='Input read DOUT' mode='1' port='135266305' mask='2' exp='.HX_DOUT' />
</flowline>
</command>
<command class_type='calculation' title='set bit counter to MSB' >
<exp exp='.bit_counter = 23' />
</command>
<command class_type='loop' title='read bit loop' type='2' exp='24' start='0' >
<flowline >
<command class_type='output' title='PD_SCK Clock output high' mode='1' port='135266305' mask='1' exp='1' />
<command class_type='input' title='Input read DOUT' mode='1' port='135266305' mask='2' exp='.HX_DOUT' />
<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
<command class_type='output' title='PD_SCK Clock output low' mode='1' port='135266305' mask='1' exp='0' />
<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
<command class_type='calculation' title='build a byte' textarea='66,10,66,10' >
<exp exp='.hx771_word_in[.bit_counter] = .HX_DOUT' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.bit_counter = .bit_counter - 1' />
</command>
</flowline>
</command>
<command class_type='comment' title='' comment='25TH clock pulse = A channel High gain' textarea='36,18,36,18' />
<command class_type='output' title='PD_SCK Clock output high' mode='1' port='135266305' mask='1' exp='1' />
<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
<command class_type='output' title='PD_SCK Clock output low' mode='1' port='135266305' mask='1' exp='0' />
<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
<command class_type='comment' title='' comment='26TH clock pulse = B Channel' textarea='36,7,36,7' disable='1' />
<command class_type='output' title='PD_SCK Clock output high' disable='1' mode='1' port='135266305' mask='1' exp='1' />
<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
<command class_type='output' title='PD_SCK Clock output low' disable='1' mode='1' port='135266305' mask='1' exp='0' />
<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
<command class_type='comment' title='' comment='27TH clock pulse  = A channel low gain' textarea='36,7,36,7' disable='1' />
<command class_type='output' title='PD_SCK Clock output high' disable='1' mode='1' port='135266305' mask='1' exp='1' />
<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='1' type='0' />
<command class_type='output' title='PD_SCK Clock output low' disable='1' mode='1' port='135266305' mask='1' exp='0' />
<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='1' type='0' />
<command class_type='comment' title='' comment='+/- sign data' textarea='12,0,12,0' />
<command class_type='calculation' title='set bit counter to MSB' >
<exp exp='.bit_counter = 23' />
</command>
<command class_type='decision' title='check if sign bit is set - then invert bits' exp='.hx771_word_in[23] = 1' swap='0' >
<flowline >
<command class_type='loop' title='invert convert loop' type='2' exp='24' >
<flowline >
<command class_type='calculation' title='Calculation' >
<exp exp='.hx711_word_out[.bit_counter] = ! .hx771_word_in[.bit_counter]' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.bit_counter = .bit_counter - 1' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='weight = &quot;-&quot;' />
</command>
</flowline>
</command>
</flowline>
<flowline >
<command class_type='loop' title='convert loop' type='2' exp='24' >
<flowline >
<command class_type='calculation' title='Calculation' >
<exp exp='.hx711_word_out[.bit_counter] = .hx771_word_in[.bit_counter]' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.bit_counter = .bit_counter - 1' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='weight = &quot;+&quot;' />
</command>
</flowline>
</command>
</flowline>
</command>
<command class_type='comment' title='' comment='build data' textarea='69,16,69,16' disable='1' />
<command class_type='calculation' title='set bit counter to MSB' >
<exp exp='.bit_counter = 23' />
</command>
<command class_type='loop' title='Loop' type='2' exp='20' start='0' >
<flowline >
<command class_type='decision' title='Decision' exp='.bit_counter = 20' swap='0' >
<flowline >
<command class_type='calculation' title='last bit - dont move LSH' >
<exp exp='.wgt = (.wgt + .hx711_word_out[.bit_counter])' />
<exp exp='' />
<exp exp='' />
</command>
</flowline>
<flowline >
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = (.wgt + .hx711_word_out[.bit_counter])' />
<exp exp='.wgt = .wgt &lt;&lt; 1 // move along 1 bit' />
<exp exp='' />
</command>
</flowline>
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.bit_counter = .bit_counter - 1' />
</command>
</flowline>
</command>
<command class_type='decision' title='' exp='.hx771_word_in[23] = 1' swap='0' >
<flowline >
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = ~ .wgt' />
<exp exp='.wgt = .wgt + 1' />
<exp exp='' />
</command>
</flowline>
<flowline />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = .wgt + .calibrate' />
</command>
<command class_type='comment' title='' comment='Auto calibrate' textarea='36,13,36,13' />
<command class_type='call' title='Call Component Macro' component='pcb_switch1' macro='ReadState' >
<return exp='.zero_swx' />
</command>
<command class_type='decision' title='Decision' exp='.zero_swx = 1' swap='0' >
<flowline >
<command class_type='calculation' title='Calculation' >
<exp exp='Zero_offset = ~ .wgt + 1' />
</command>
</flowline>
<flowline />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = .wgt + Zero_offset' />
</command>
<command class_type='comment' title='' comment='scale' textarea='12,0,12,0' />
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = .wgt * .scale' />
</command>
<command class_type='calculation' title='count average weight' >
<exp exp='.wgt_ave = .wgt_ave + .wgt' />
</command>
</flowline>
</command>
<command class_type='comment' title='' comment='calculate average' textarea='12,0,12,0' />
<command class_type='calculation' title='Calculation' >
<exp exp='.wgt = .wgt_ave / .Average_count' />
</command>
<command class_type='calculation' title='Calculation' >
<exp exp='.Return = ToString$ (.wgt)' />
</command>
</flowline>
</macro>
</macros>
<variables >
<variable public='0' >
<def class_type='variable' name='weight' type='T8' description='measure weight' isconst='0' isinit='1' usrinit='&quot;&quot;' setinit='&quot;&quot;' >
<array size='10' />
</def>
</variable>
<variable public='0' >
<def class_type='variable' name='Zero_offset' type='s32' description='zero offset auto cal value' isconst='0' isinit='1' usrinit='0' setinit='0' />
</variable>
</variables>
</root>
