-
Is it possible to interpret non-standard serial data with PicBasic (sample attached)
I have some remotely managed studio strobe, it has keyboard, and when pressing numerical keys, the following sequences being transmitted on single wire, as shown on the picture. What protocol is this, and can I somehow interpret it, using picbasic pro?
http://i.imgur.com/1QPLqSU.jpg
Width of wide pulse is 1.9msec, and width of narrow pulse is 642usec.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
It looks like some kind of binary coding judging by the number entered and the output stream. Why not ask the manufacture for the protocol?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
hi dave,
it reminds me of a sort of binary encoding...
0= no missing pulse 0000
1= 1 missing pulse in the "ones" position 0001
2= 1 missing pulse in the "twos" position 0010
3= ones missing and twos missing 0011
4= 1 missing pulse in the fours position 0100
5= ones and fours missing 1001
it would help to see all the way up to 9
do you also need to decode other letter/function key/enter/backspace etc. etc. characters??
I don't recognize the protocol off hand but then I am no protocol expert.
perhaps some sort of digital logic analyzer that has a good interpreter behind it would help.
something like this... https://www.saleae.com
I have never used the saleae but I know it comes highly regarded for it's price.
good luck
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Yes is goes up that way, I can record it up to 9, but you are correct, it looks like plain BCD code, but the rendering of "0" and "1" with pulses, looks weird for me. I have saelae logic analyzer, but it can't detect these pulses at all, I've used scope to record them.
In fact, I want very simple thing - say, set variable ENABLE=0, when "zero" is transmitted, and ENABLE=1, when any other digit is being sent. I'm not looking for character decoding or whatsoever.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
I was suggested, that this is PPM (Pulse Position Modulation), used in some IR/RF remotes and telemetric control equipment. Datasheet of Holtek HT6222 shows quite similar, but not exact diagram of signal.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
If you need only ENABLE use count to count pulses.
Try something like this:
Code:
COUNT Pin, Period, Var
If Var<xxx then
enable=1
else
enable=0
endif
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
But pulses are of different width in series, will it work?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Just checked, it works, but not as it should - even on same sequence, it always reads different values.
Code:
taki:
COUNT PORTC.4, 70, LABEL
if label=0 then
goto taki
endif
LCDOUT $FE,$c0, DEC(LABEL), " "
PAUSE 5
GOTO TAKI
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
try this:
taki:
While PORTC.4=0
WEND
COUNT PORTC.4, 70, LABEL
LCDOUT $FE,$c0, DEC5 LABEL
PAUSE 5
GOTO TAKI
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
The actual issue is different I guess.
The system used is IDPPM - Differential Pulse Position Modulation.
Now I changed algorithm, and it detects pulses, there are 34 pulses, and it does it properly. But quantity of pulses is always 34, only pauses between them change, so COUNT is not proper implementation I guess.
P.S. above code displays only 00000
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
I was thinking that 1 is represented with missing pulse.
You can try something like this
Code:
DEFINE PULSIN_MAX 65535 ' Limit wait-for-pulse and maximum-pulse count
While PORTC.4=0 'wait for rising edge of start pulse
WEND
FOR I=0 TO 33
PULSIN PORTC.4,0,W3
IF W3>XXX THEN GOTO GotData
NEXT I
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
A side note, a statement like
IF PORTC.4=1 THEN
actually sets PORTC.4 high.
Is this bug or feature?
I've added 1 transistor signal inverter, but no help. Also, your code does not work.
OK, I will give up with this idea.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
This, to me, is the classic problem of how to tell (program) your micro controller to recognize and interpret the pattern.
The human brain combined with an eyeball can recognize it... now you just need to figure out how to translate that into code.
I would start by watching for the start pulse, which is longer than the other pulses. Then keep track of the width of the following pulses (or the width of the "low" part. Then watch for one or more extended "low" pulses.
Since you only need to differentiate between 0 and any other number/key press, then just watch for an extended "low" in a given time period after the extended "high" start pulse. If in the given time period you do not get any extended "low" pulses then the digit is "0" other wise if you get an extended "low" pulse then the keypress was non-zero.
Since the quantity of pulses in each character is always 34 then you should be able to just set up a counter to increment whenever the pulse is low and stop incrementing when the pulse goes back high. Then if the counter has incremented above a certain threshold then that particular "low" pulse was a "wide" one and indicates a non zero digit. (I hope that makes sense)
I believe it is easily do-able. you just need to distill it down to how to detect the extended low pulse that indicates a non-zero digit pressed.
that is how I would attack the challenge.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Code for that is in post #11 except it waits for transition from low to high to start measure 34 low intervals.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Yes, I know how to implement detection logically, I have no issues with algorithm, but I can't implement it in hardware, also, I can't understand, why statement
IF PORTC.4=1
or
IF PORTC.4=0
makes corresponding pin high or low?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Quote:
IF PORTC.4=1
or
IF PORTC.4=0
makes corresponding pin high or low?
I highly doubt that. I don't know how you're testing it, but if that's the case things are seriously broken.
You likely have some other issue.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
The IF statement per se should not and I'm pretty sure does not twiddle the pin but if what you you're doing is somehing like...
Code:
If PortC.4 = 0 THEN
PortC.1 = 1
ENDIF
...and there happens to be analog functions on the pins which you haven't disabled then the actual state of PortC.4 isn't read correctly and you're getting into the classic RMW issue where the "invalid" state of PortC.4 is being written back to PortC.4 when the write operation to PortC.1 occurs but without seeing the rest of the code it's hard to say for sure.
/Henrik.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Here is the complete code:
Code:
Include "modedefs.bas" ' Include serial modes
TRISA = %11111111 ' Set PORTA to all input
TRISC = %00000000 ' Sets all PortB pins to output
ADCON1 = %10000101 ' Set PORTA analog and right justify result
ADCON0=%00000000
low portc.4
low portc.5
X VAR PORTC.4
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 1500
DEFINE LCD_DATAUS 44
DEFINE OSC 4
lcdout "test 2"
PAUSE 500
LABEL VAR WORD
DROEBITI VAR WORD
taki:
if portc.4=0 then
COUNT PORTC.4, 60, LABEL
endif
if label=0 then
goto taki
endif
LCDOUT $FE,$c0, DEC(LABEL), " "
GOTO TAKI
I have source of signal (chip with name grinded off, but holtek logo is recognizable), which is connected directly to PORTC.4. Also, scope is connected to same pin.
As long as I introduce the statement "if portc.4=0 then"
If it is "=0" then pin is sunk to ground, so no pulses can be detected, and nothing can be seen on scope. If it is "=1", then pin gets driven high, and no pulses can be seen with scope or read too.
Chip is 16F870.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Code:
TRISA = %11111111 ' Set PORTA to all input
TRISC = %00000000 ' Sets all PortB pins to output
ADCON1 = %10000101 ' Set PORTA analog and right justify result
ADCON0=%00000000
low portc.4
low portc.5
Is there something strange here?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Easy! It’s giving you a wider pulse duration at the start to qualify the incoming data.
From there you only need to sample 32 times at the correct interval.
So look for that, then read it in with a 32 step loop.
Code:
bitcode var byte[32]
count var byte
pulseduration var byte
pulseduration = time from peak to peak
for count = 0 to 31
bitcode[count] = inputpin
pause pulseduration
next count
Of course, better ways than reading into a 32 byte array, but quickest.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
You're omitting an important thing - MCU has own clock, wastes different time on program execution, but incoming data is sent async, so it can't wait for MCU to become ready, so my guess, how it all should work, is as follows:
As pulse arrives, we start recording it as fast as possible, after pulse sequence finished, we just count numbers of 1's and 0's recorded, and based on that, decide what to do with decoded data. Considering total sequence duration and speed, I guess, external sram or eeprom might be needed?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
That depends. You didn’t display the duration.
If it’s several uS duration pulses, the falling edge of the first longer pulse is the place to mark time,
then waste half a pulse duration before the for-next loop. If you can roughly synchronise from the first pulse (which is what it’s for),
it takes time for the two clocks to drift apart.
If you were to sample bits as fast as you can, you’d still want to do that from the falling edge of the first pulse.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Does your hardware have the LCD that is in your code?
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
That should get the 32 bits straight into a four byte array.
Code:
'
main:
@ clrwdt
'
if portc.4 = 1 then ‘ count initial pulse duration
leadcnt = leadcnt + 1
else
leadcnt = 0
endif
'
'
if leadcnt > expectedduration then' qualify initial pulse duration
burst: ' sync to initial pulse falling edge
if portc.4 = 1 then
@ clrwdt
goto burst
endif
'
for rotcnta = 0 to 3 ' shift data into 32 bit buffer
databuffer = 0
for rotcntb = 0 to 7 ‘ shift data to each byte
databuffer.bit0 = portc.4
databuffer = databuffer << 1
dataarray[rotcnta] = databuffer
pauseus peaktopeakduration
next rotcntb
next rotcnta
‘
leadcnt = 0
endif
'
goto main
‘
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
surely a candidate for timer1 and gate control
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Currently I have LCD connected, for debugging purposes, but in final device, I will have no LCD.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
So this is how initial things should work, as I see it:
1. We sent interrupt on rising edge of PORTC.4
2. As PORTC.4 gets high, timer is started, and counts to predefined value (width of 1st pulse)
3. While timer is running, PORTC.4 is still being continuously checked, to determine, whenever it is still high. It should be high while timer is counting, if it gets low, while timer is on, this means, this is not proper pulse, so we should reset and start everything over.
4. If timer counting ended, and PORTC.4 was high all that time, this means that sync pulse was captured correctly, and we're ready for the next step.
This appears quite simple in words, but all Greek for me, in code :), so far, my practical experience with timers and pwm is light dimming, and playing polyphonic tunes via it :D
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Or Timer1 and Interrupt on Change or even better Interrupt on PortB.0 and use of Option_reg.6 to select which edge is expected to arrive and trigger the interrupt.
Needs a bit of work in the interrupt routine...
Ioannis
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Indeed, but lack of knowledge.... :)
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Going totally crazy, can't figure out what to do and how :(
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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
-
1 Attachment(s)
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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
Attachment 8317
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Here's one idea:
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
I can't compile this let alone test it but it serves to show the genereal idea of a software only solution.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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.
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
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
-
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
this works better the first one did no work for sequential 1's
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[14]=1
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= %11010001
for x = 0 to 31
while tmr2 :wend
if darta.0[x] then
MDCON.0 = 0
while tmr2 :wend
pauseus 6
while tmr2 :wend
pauseus 6
MDCON.0 = 1
while tmr2 :wend
pauseus 6
else
MDCON.0 = 1
endif
next
modout=1
MDCON= 0
pauseus 600
modout = 0
PAUSE 200
goto Main_Loop
end
-
1 Attachment(s)
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
-
1 Attachment(s)
Re: Is it possible to interpret non-standard serial data with PicBasic (sample attach
Wow! Such an input.
Here are signal details. Actual signal is high and goes low, on my last picture, I've inverted it just for ease of viewing and analyzing.
On the picture below, I've specified all timings as required.
Attachment 8320