Indeed, but lack of knowledge....![]()
Indeed, but lack of knowledge....![]()
Code that works - It differentiates "0" from any other command:
Code:UIDEDA: if pulsi=0 then FOR N=0 TO 300 'main loop duration IF PULSI=0 THEN A=A+c 'count positive edges c=0 'stop increasing 1 after first loop d=1 'set increase for 0 ELSE B=B+d 'count 0 volt d=0 'stop increasing 0 after first loop c=1 'set increase for 1 ENDIF NEXT IF A<>0 AND B<>0 THEN lcdout $FE,2, "A=",#A, " " lcdout $FE,$C0,"B=",#B, " " ENDIF if a=7 and b=8 then high natura 'on if a=6 and b=7 then low natura 'off A=0 B=0 endif GOTO UIDEDA
Now I want to ad an array, where, when "1" occurs, value of N variable will be stored, which later can be counted, and position of "1" s and "0" -s detected.
Going totally crazy, can't figure out what to do and how![]()
Logically, code should look like this:
WAIT FOR LOW LEVEL AND MEASURE IT'S DURATION
IF LOW LEVEL LENGTH=10MS THEN MEASURE HIGH LEVEL DURATION AFTER IT
IF HIGH LEVEL DURATION WAS 2MS, THEN GO TO NEXT STEP, ELSE, LOOP THIS CYCLE AGAIN
NEXT LEVEL:
CONSIDER 600US LOW LEVEL AS 1, AND 2MS LOW LEVEL AS 0, WRITE THEM SEQUENTALY TO 32 BIT ARRAY, UNTIL 32 BITS WRITTEN
EXTRACT MSB AND LSB FROM ARRAY
CONVERT TO WORD
Or, more "programmer" approach. Assuming "A" is the input pin:
START COUNTING
A=0, B=0
WHILE A=1, B=B+1
WHILE A=0, C=C+1
IF B=500 AND C=100 THEN CONTINUE, ELSE, START OVER
B=0 C=0
FOR N=1 TO 32
WHILE A=1, B=B+1
WHILE A=0, C=C+1
IF B=50 AND C=50 THEN CONTENTS[N]=1
IF B=50 AND C=150 THEN CONTENTS[N]=0
A=0, B=0
NEXT N
![]()
Here's one idea:I can't compile this let alone test it but it serves to show the genereal idea of a software only solution.Code:HighTime VAR WORD LowTime VAR WORD BitArray VAR WORD [2] LSB VAR BitArray.LowWord MSB VAR BitArrat.HighWord WaitForStartBit: GOSUB MeasureLow IF (LowTime < 9500) OR (LowTime > 10500) THEN WaitForStartBit ' 9.5-10.5ms qualifies GOSUB MeasureHigh IF (HighTime < 1500) OR (HighTime > 2500) THEN WaitForStartBit ' 1.5-2.5ms qualifies NextLevel: For i = 0 to 31 GOSUB MeasureLow IF (LowTime > 400) AND (LowTime < 800) THEN BitArray.0[i] = 1 ' 500-700us qualifies as 1 IF (LowTime > 1700) AND (LowTime < 2320) THEN BitArray.0[i] = 0 ' 1800-2200us qualifies as 0 NEXT LCDOUT $FE,$01, "HighWord", DEC MSB LCDOUT $FE,$C0, "LowWord", DEC LCB Pause 1000 Goto WaitForStartBit MeasureLow: LowTime = 0 While Signal = 1 : WEND ' Wait for low level While Signal = 0 ' Measure low level LowTime = LowTime + 100 ' Resolution is 100us, change if needed PauseUS 92 ' Tweak to calibrate, depends on actual loop time WEND RETURN MeasureHigh: HighTime = 0 WhileSignal = 0 : WEND ' Wait for low While Signal = 1 ' Measure high level HighTime = HighTime + 1 ' Resolution is 100us, change if needed PauseUS 92 ' Tweal to calibrate, depends on actual loop time WEND RETURN
Thanks, will give it a try tomorrow.
My oscilloscope can record in .csv format, is it possible in some emulator to "play back" this recording, and feed it to virtual chip? So I can test and debug without using original hardware, which generates these pulses.
Bookmarks