Going totally crazy, can't figure out what to do and how![]()
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.
the waveform is simple to simulate like this is you have a chip with a dsp module.
note the timings are estimated since the curious one's info is lacking most of the meaningful detail
Code:'**************************************************************** '* Name : MODULATOR.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2016 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 5/29/2016 * '* Version : 1.0 * '* Notes : * '* : 16F1825 * '**************************************************************** #CONFIG __config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF __config _CONFIG2, _PLLEN_ON & _LVP_OFF #ENDCONFIG OSCCON=$70 DEFINE OSC 32 ' PIC 16F1825 TRISA = %111111 ' Make all pins Input trisc = %101111 ;Make all pins Input ANSELA=0 ANSELC=0 MDSRC= %00000000 MDCARH =%11000100 MDCARL =%00000000 X VAR byte darta VAR byte[4] TIMER1 VAR WORD EXT clear modout var latc.4 darta.0[15]=1 hpwm 1,128,1600 MDCON.0 = 0 modout =0 Main_Loop: modout=1 pauseus 8000 modout =0 while tmr2 :wend MDCON= %11000000 for x = 0 to 31 while tmr2 :wend MDCON.0 = ! darta.0[x] next modout=1 MDCON= 0 pauseus 600 modout = 0 PAUSE 200 goto Main_Loop end
Last edited by richard; - 7th October 2016 at 05:50.
Warning I'm not a teacher
Bookmarks