fl hex { Data Logger for Modified Digital Tester P-10 [RS232(2400bps,8bit,NoParity,1StopBit)] 2013/02/22 15:24:23 Isolation between Propeller and P-10 (There is inside P-10 Tester) Propeller Tester(P-10) 3.3V(Prop) Vcc(P-10) | | 220ohm 100ohm | PC621(P-10) | | --------- | P27 -----------|4 1|------- Tx(P-10) | | GND(Prop)---- -|3 2|---GND(P-10) --------- Using GraphicLCD(DMF-51026NY-LY) Propeller DFM-51026NY-LY P0 ---------- FLM P1 ---------- LP P2 ---------- CP P3 ---------- M P4 ---------- D0 P5 ---------- D1 P6 ---------- D2 P7 ---------- D4 P8 ---------- DISPOFF P9 ---------- -9V_on P10 --- Output for Counter-Mode(DUTY single-end) P10 --- Input fot Counter-Mode(LOGIC A) Using VR for TimeScale&FullScale (RCdecade curcuit) P24 ---------------------- | | | | | | | | |--->VR Capacitor 10kohm 0.01uF | | 100ohm | | | GND GND Switch for selection(TimeScale&FullScale) 3.3V | | 10kohm P25 -------| | GND } \ a cog special register [ifndef ctra h1F8 wconstant ctra ] [ifndef ctrb h1F9 wconstant ctrb ] [ifndef frqa h1FA wconstant frqa ] [ifndef frqb h1FB wconstant frqb ] [ifndef phsa h1FC wconstant phsa ] [ifndef phsb h1FD wconstant phsb ] \ allocate string \ ( -- ) : s, parsenw dup C@ 1+ bounds dup rot2 do C@++ c, loop drop ; \ Transmitted data from P-10 wvariable P10_array d12 allot \ variable for saving string's address wvariable str_addr \ another variable for vidX/vidY wvariable vidXX wvariable vidYY \ Selection for FullScale&TimeScale wvariable FS wvariable TS \ LCD-display-number-font \ blank,0,1,2,3,4,5,6,7,8,9,L wvariable LCD_number -2 allot h00 c, h7D c, h05 c, h5B c, h1F c, h27 c, h3E c, h7E c, h15 c, h7F c, h3F c, h68 c, \ Strings on graphicLCD wvariable scale -2 allot s, FullScale: s, TimeScale: wvariable time -2 allot s, 1min s, 10min s, 1hr s, 10hr s, 24hr wvariable R -2 allot s, 1k s, 10k s, 100k s, 1M s, 10M wvariable V -2 allot s, 1V s, 5V s, 20V s, 100V s, 400V wvariable uA -2 allot s, 10uA s, 100uA s, 500uA s, 1000uA s, 2000uA wvariable mA -2 allot s, 10mA s, 20mA s, 50mA s, 100mA s, 200mA \ each time ticks 1min,10min,1hr,10hr,24hr wvariable ticks -2 allot d375 l, d3750 l, 22500 l, d225000 l, d5400000 l, lockdict create hdserialRx forthentry $C_a_lxasm w, h124 h113 1- tuck - h9 lshift or here W@ alignl h10 lshift or l, z8iQ3B l, z20yPO8 l, z2WyPj8 l, z8iQBB l, z2WyPO0 l, z2WiPuG l, zbyPr2 l, z20iPuG l, z3jFQBH l, z3nFQBH l, z20iPyk l, z3riPuG l, z1YFQFl l, zbyPO1 l, z1vyPQ0 l, z3[yPnU l, z1SV01X l, freedict \ VR for Selection(TimeScale and FullScale) d24 wconstant VR \ switch for selection(TimeScale,FullScale) d25 wconstant sw sw >m constant swm \ Time constant variable Time -4 allot d375 l, d3750 l, d22500 l, d225000 l, d540000 l, variable dT \ StatusFlag for receiving data frpm P-10 \ bit10 bit9 bit8 bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0 \ M k m u A V ohm minus DC AC valid wvariable status \ Current status during logging wvariable current \ Floating-point position wvariable point \ 4-digite(4bytes) on P-10 tester's display variable value { half duplex serial structure 00 - 04 -- rx bitticks 04 - 08 -- tx bitticks 08 - 0C -- rx pin mask 0C - 10 -- tx pin mask } \ hdserialStruct ( rxbaud txbaud rxpin txpin -- ) : hdserialStruct lockdict variable hC allot lastnfa nfa>pfa 2+ alignl freedict tuck swap >m swap hC + L! tuck swap >m swap h8 + L! tuck swap clkfreq swap u/ swap h4 + L! swap clkfreq swap u/ swap L! ; \ HalfDuplex [Receive 2400bps P23 Transmitt 2400bps P23 (Not Used) ] d_2400 d_2400 d_23 d_23 hdserialStruct ser \ Display string(setted by WORD"s,") to graphicLCD \ ( n1 n2 -- ) n1:string index n2:string's top address \ Set charcter position(vidX=0-d19 vidY=0-7) before call : gr_dispstr swap dup 0 <> if 0 do dup C@ + 1+ loop else drop then grlcd_str ; \ Get number from display-data-font on P10's LCD \ ( n1 -- n2 ) n1:byte-number(1,3,5,7) n2:number \ d10 express character"L". : getNumber \ Get segment-data of font on LCD P10_array swap 2dup + C@ 7 and 4 lshift \ Get upper4bit rot2 1+ + C@ hF and \ Get Lower4bit or \ Get number from segment-data of font LCD_number d12 0 do 2dup \ Get number(0,1,2,3,4,5,6,7,8,9,d10,d11) i + C@ = if i rot2 d11 seti 2drop then loop \ minus is blank, "0,1,2,3,4,5,6,7,8,9" are numbrt, d10 id "L" 1- ; \ display string to graphicLCD ( cstr -- ) \ Set charcter position(vidXX=0-d19 vidYY=0-7) before call : grlcd_str1 C@++ dup if bounds do i C@ vidXX W@ vidYY W@ grlcd_char \ Calculate vidXX and vidYY vidXX W@ 1+ dup d20 = if drop 0 vidXX W! vidYY W@ 1+ dup 8 = if drop 0 vidYY W! else vidYY W! then else vidXX W! then loop else 2drop then ; \ Print character and vidXX-1 \ ( n -- ) n:character : print_char_vidXX-1 vidXX W@ 0 grlcd_char vidXX W@ 1- vidXX W! ; \ Print character and vidXX+1 \ ( n -- ) n:character : print_char_vidXX+1 vidXX W@ 0 grlcd_char vidXX W@ 1+ vidXX W! ; \ Update status \ ( n1 n2 -- ) n1:setting bit data n2:mask value : update_status status W@ and or status W! ; \ Display data from P-10 to graphocLCD \ ( -- ) : P-10_data begin ser hdserialRx \ Search for first serial data dup hF0 and h10 = if P10_array C! d13 0 do ser hdserialRx i 1+ P10_array + C! loop \ d14 0 do i P10_array + C@ . loop cr 0 vidXX W! 0 vidYY W! \ Check if invalid data ( Diode,speker,HOLD,Battery,Hz,%) 9 P10_array + C@ h5 and d10 P10_array + C@ h5 and or \ n diode d11 P10_array + C@ hB and or \ % speaker d12 P10_array + C@ h3 and or 0= \ relative HOLD if \ Clear Top-line vidMem d80 clear_vram \ Clear vidMem(80words=160bytes) status W@ hFFFE and status W! \ valid \ AC or DC or Resistor P10_array C@ dup hC and if hC and 8 = if \ Display "AC" c" AC " grlcd_str1 2 hFFFB update_status \ Set AC flag else \ Display "DC" c" DC " grlcd_str1 4 hFFFD update_status \ Set DC flag then 3 vidXX W! else drop status W@ hFFF9 and status W! \ Set ohm flag then \ Sign P10_array 1+ C@ 8 and if h2D status W@ 8 or status W! \ Sign minus else h20 status W@ hFFF7 and status W! \ Sign plus then \ Set initial floating-point to 0 0 point W! \ 4-digits \ point= 3 when lcd is 1.234 \ point= 2 when lcd is 12.34 \ point= 1 when lcd is 123.4 \ point= 0 when lcd is 1234 4 0 do i 2 u* 1+ dup i 0 <> if \ Add 3,5,7 to P10_array P10_array + C@ h8 and if 4 i - point W! then else drop then \ number getNumber dup 0< if 2drop \ Skip when P-10's display is "OL" 3 seti \ Finish loop \ Display "OL" c" OL " grlcd_str1 6 vidXX W! 0 \ Set "OL" flag else \ value(4bytes) has 4digits dup value i + C! h30 + i 3 = if 1 then \ Set Not"OL" flag then loop \ Display Sign and 4-digits and floating point ( Skip if "OL") if vidXX W@ 5 + vidXX W! 5 0 do i point W@ = if \ Display floating point h2E print_char_vidXX-1 then print_char_vidXX-1 loop vidXX W@ 7 + vidXX W! then \ unit (u, k) P10_array 9 + C@ hF and dup 0<> if 8 = if \ Displau unit"u" h75 print_char_vidXX+1 \ Set unit'u' Clear unit 'k' h80 hFDFF update_status else \ Displau unit"k" h6B print_char_vidXX+1 \ Set unit'k' Clear unit'u' h200 hFF7F update_status then else drop \ Clear unit 'u and k' status W@ hFD7F and status W! then \ unit (n, M) P10_array d10 + C@ hF and dup 0<> if 8 = if \ Displau unit"m" h6D print_char_vidXX+1 \ Set unit'm' Clear unit'M' h100 hF97F update_status else \ Displau unit"M" h4D print_char_vidXX+1 \ Set unit'M' Clear unit'm' h400 hFC7F update_status then else drop \ Clear unit 'M and m' status W@ hFAFF and status W! then \ unit (ohm) P10_array d11 + C@ hF and 4 = if \ Displau unit"ohm" h7F print_char_vidXX+1 \ Set unit'ohm' status W@ 10 or status W! else \ Clear unit'ohm' status W@ hFFEF and status W! then \ unit (V, A) P10_array d12 + C@ hF and dup 0<> if 8 = if \ Displau unit"A" h41 print_char_vidXX+1 \ Set unit'A' Clear unit'V' h40 hFFDF update_status else \ Displau unit"V" h56 print_char_vidXX+1 \ Set unit'V' Clear unit'A' h20 hFFBF update_status then else drop \ Clear unit 'A and V' status W@ hFFF9 and status W! then else c" Out of Measurement" grlcd_str1 status W@ 1 or status W! \ invalid then else drop then 0 until ; \ Get VR-value by using RC-Decay VR=10kohm C=0.01uF \ ( -- n) n:0,1,2,3,4 : getVR h20000000 VR + ctra COG! \ Set "POS detector" mode 1 frqa COG! VR dup pinout pinhi \ Set VR-port to Output(Hi) 0 phsa COG! VR pinin \ Set VR-port to Input begin ina COG@ 1 VR lshift and 0= until phsa COG@ \ dup . dup d10000 > if drop 4 else dup d8500 > if drop 3 else dup d6500 > if drop 2 else d4600 > if 1 else 0 thens ; \ Check if current P-10's state is different from status at start \ ( -- n ) n:t/f true indicate status don't change : status? status W@ current W@ = ; \ Check if switch is pushed \ ( -- n ) n:t/f true indicate swich isn't pushed : sw_state? ina COG@ swm and ; \ Select item from strings \ ( n1 -- n2 ) n1:string address n2:item number : select str_addr W! vidX W@ begin dup vidX W! 1 vidY W! getVR dup str_addr W@ gr_dispstr c" " grlcd_str \ Break if current is different from status status? if sw_state? if drop 0 else nip 1 then else drop 1 then until ; \ Set X/Y to Fullscale/TimeScale's line \ ( -- ) : scale_line 0 vidX W! 1 vidY W! ; \ Get range from status \ ( -- n ) n:selected raange's string address : desire_String status W@ 6 and if status W@ h40 and if \ Current status W@ h100 and if \ mA mA else \ uA uA then else \ Voltage V then else \ Resistor R then ; variable sum \ Calculate number inside value(4bytes) \ There is 4-digits inside value(4bytes) \ There is 4-digits inside value(4bytes) \ ( -- n1 ) n1:percent number : calc_value 0 sum L! point W@ 0= if \ no floating-point 4-digits 1 value 3 + 4 0 do 2dup C@ u* sum L@ + sum L! 1- swap d10 u* swap loop else \ floating-point is 1/2/3 \ point=3 3digits 1.234 \ point=2 4digits 12.34 \ point=1 4digits 123.4 1 value 3 + point W@ 2- 0 max - 5 point W@ 1- - 4 min 0 do 2dup C@ u* sum L@ + sum L! 1- swap d10 u* swap loop then 2drop \ ." calc_value:" sum L@ . cr \ Check if mode is resistor status W@ h10 and 0 <> if \ Check if current resister range is k/M/nothing status W@ h600 and 0<> if \ Unit is "k" or "M"? status W@ h200 and 0<> if \ Unit "k" point W@ 1 = if \ ( Unit "k" multiply d100 because sum is 10-times ) d100 else \ ( Unit "k" multiply d10 because sum is 100-times ) d10 then else \ Unit "M" point W@ 1 = if \ ( Unit "M" multiply d10000 because sum is 10-times ) d10000 else \ ( Unit "M" multiply d1000 because sum is 100-times ) \ (mltiply d10 because of display-change[300.0k-->0.300M) \ d1000 d10000 then then sum L@ u* else \ nothig for k,M sum L@ point W@ 1 = if d10 else d100 then u/ then d100 u* \ Calculate divider number d1000 FS W@ dup 0= if \ FS=1k drop else \ FS= 10k, 100k, 1M, 10M 0 do d10 u* loop then \ Get persent expression u/ d100 min \else then ; \ Set dT to phsb \ ( -- ) : set_dT dT L@ negate phsb COG! ; wvariable pre_point \ Check if current point is different from pre_point \ ( -- ) : point_check point W@ pre_point W@ <> if d1000 delms point W@ pre_point W! then ; : Logger BASE 8 + pinout \ Disable graphicLCD BASE 9 + pinout \ Disable -9V c" vidMem BASE DFM-51026" 0 cogx \ Drive graphicLCD BASE 9 + pinhi \ Enable -9V c" P-10_data" 1 cogx BASE 8 + pinhi \ Enable graphicLCD begin vidMem d160 + d560 clear_vram \ Clear vidMem(560words=1120bytes) \ Stop if "Out of Measurement" begin status W@ 1 and 0= until \ Save current state ("status" is recorded by WORD"P-10_data") status W@ current W! \ Select FullScale(Current/Voltage/Resistor) scale_line 0 scale gr_dispstr desire_String select FS W! \ Break if current is different from status status? if \ state do NOT change \ Wait until sw is off begin sw_state? 0 <> until \ Select TimeScale scale_line 1 scale gr_dispstr time select TS W! \ Break if current is different from status status? if \ state do NOT change \ Clear scale_line vidMem d160 + d80 clear_vram \ Display FullScale scale_line c" FS:" grlcd_str FS W@ desire_String gr_dispstr \ Display TimeScale d10 vidX W! 1 vidY W! c" TS:" grlcd_str TS W@ time gr_dispstr \ Save current point to pre_point point W@ pre_point W! \ Clear grdata-array d80 0 do 0 grdata i 2 u* + W! loop \ Display graphic begin \ Set loop-delay \ Set counterA to Duty single-ended h18000000 d10 + ctra COG! d10 pinout d53686 frqa COG! \ Set counterB to LOGICA h68000000 d10 + ctrb COG! 1 frqb COG! Time TS W@ 4 u* + L@ dT L! d160 0 do set_dT \ Check if current point is different from pre_point point_check calc_value \ Save data to grdata-array and plot on Graphic i grdata + C! i plot begin phsb COG@ 0 < if \ Break if current is different from status status W@ dup h10 and 0<> if \ R-range h1FF and current W@ h1FF and <> if d160 seti 1 else 0 then else \ Except for R-range drop status? 0= if d160 seti 1 else 0 then then else 1 then until loop \ Shift Graphic-area to left begin \ Set dT again set_dT point_check \ Shift d159 data and d159 dots gr_shift \ Plot d160th dot calc_value d159 grdata + C! d159 plot begin phsb COG@ 0 < if \ Break if current is different from status status W@ dup h10 and 0<> if \ R-range h1FF and current W@ h1FF and <> if 1 1 else 0 then else \ Except for R-range drop status? 0= if 1 1 else 0 then then else 0 1 then until until \ Break if current is different from status status W@ dup h10 and 0<> if \ R-range h1FF and current W@ h1FF and <> if 1 else 0 then else \ Except for R-range drop status? 0= if 1 else 0 then then until then then fkey? swap drop \ st? until \ LCD-off BASE 8 + pinlo \ Disable graphicLCD BASE 9 + pinlo \ Disable -9V 1 cogreset 0 cogreset ; decimal { \ Communication between Propeller and P-10 fl build_BootOpt :rasm \ treg6 - serpin mask \ treg5 - bitticks \ treg4 - cnt nextbit \ treg1 - serialStruct \ stTOS - Receiving data rdlong $C_treg5 , $C_stTOS add $C_stTOS , # h8 \ \ receive bit counter \ mov $C_treg3 , # d_8 \ rdlong $C_treg6 , $C_stTOS \ \ serpin as input \ \ andn dira , $C_treg6 \ \ data byte \ mov $C_stTOS , # 0 \ \ first loop tick count, 1.25 bit times so we sample closer to the middle \ necessary in the assembler routine, in the forth routine, the delays of the loop setup \ make this unecessary so we only use 1 bit time \ mov $C_treg4 , $C_treg5 shr $C_treg4 , # 2 add $C_treg4 , $C_treg5 \ \ wait for a hi to lo transition \ waitpeq $C_treg6 , $C_treg6 waitpne $C_treg6 , $C_treg6 \ \ first loop tick count \ add $C_treg4 , cnt __rxloop waitcnt $C_treg4 , $C_treg5 test $C_treg6 , ina wz \ shr $C_stTOS , # 1 muxnz $C_stTOS , # h_80 \ djnz $C_treg3 , # __rxloop \ jexit ;asm hdserialRx }