fl { This is translated Single Pin Sigma Delta Driver v1 by Beau Schwabe to PropForth5.5 2013/07/17 16:12:42 } \ Single Pin Sigma Delta Driver v1 \ ( n1 n2 n3 -- ) n1:ADC accumlator address n2:samples n3:A/D pin number lockdict create a_1pin_sigma_delta_A/D forthentry $C_a_lxasm w, h124 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z2WyPW1 l, zfiPZB l, z1SyLI[ l, z2WiPeB l, z1SyLI[ l, z1[ixmC l, z2WyPr0 l, z2WiPmD l, z1YFPal l, z1rixZC l, z1bixmC l, 0 l, z1[ixmC l, z20oPr1 l, z3[yPnR l, z8FPuB l, z1SV04P l, freedict variable result clkfreq d10 u/ constant 100msec \ Convert VR's center voltage to 0 - 4095 100msec by 100msec \ ( -- ) : a/d_VR c" result d4095 6 a_1pin_sigma_delta_A/D" 0 cogx cnt COG@ 100msec + begin result L@ . cr 100msec waitcnt fkey? swap drop until 0 cogreset ; { \ 1-pin SigmaDelta A/D converter \ ( n1 n2 n3 -- ) n1:ADC accumlator address n2:samples n3:A/D pin number \ $C_treg1 -- ADC Pin mask \ $C_treg2 -- samples \ $C_treg3 -- counter \ $C_treg4 -- accumlator \ $C_stTOS -- ADC accumlator address fl build_BootOpt :rasm \ Get ADC Pin mask mov $C_treg1 , # 1 shl $C_treg1 , $C_stTOS spop \ Get samples mov $C_treg2 , $C_stTOS spop \ Set ADC pin to an input andn dira , $C_treg1 __1 \ Clear ADC_Sample mov $C_treg4 , # 0 \ Set number of itterations mov $C_treg3 , $C_treg2 __2 \ Read ADC pin ; set Z flag test $C_treg1 , ina wz \ reset ADC pin to opposite state of ADC pin reading muxz outa , $C_treg1 \ Set ADC pin to an output or dira , $C_treg1 \ small delay for charging/discharging nop \ Set ADC pin to an input andn dira , $C_treg1 \ Increment ADC_accumulator only if cap needed charging if_nz add $C_treg4 , # 1 \ next itteration djnz $C_treg3 , # __2 \ write ADC_accumulator back to Spin variable "sample" wrlong $C_treg4 , $C_stTOS \ read next ADC sample jmp # __1 ;asm a_1pin_sigma_delta_A/D }