Pelco D sending

tmack

Member
In the past ,with your help I was able to build a Pelco D protocall decoder using a picaxe 18x which is at this link:

http://www.picaxeforum.co.uk/showthread.php?t=9773&highlight=pelco

I am wondering if I could get any help building a controller that would send out Pelco D protocall when switches are pressed.
I am just getting back into using the Picaxe so I may be slow in understanding but I would appreciate any help you can give.

In my last thread Hippy wrote: "That should be pretty straight forward. Just put what you need to send in a few byte variables, add those up to create a valid checksum and send those variables using SEROUT at the right baud rate.

If you need further help I can come back to this if you want ( bit busy at the present time )."

Unfortunately the only parts I really understand are are the SEROUT and baud rates....Ill try and start looking at some code as a starting place. I am hopeing someone can help me get from there to where I want to be. Thanks for any help/advice3. T
 

tmack

Member
The working reciever code:

' this code works for DECODING Pelco "D"
'Pelco D Protocal Decoder FOR PICAXE 18X
'Rs232 coming from pin 3 in computer to a 10K/22K joint,
'other side of the 10K goes to ground otherside of 22K goes to pin 2
'output side of the 18X goes to bank of LEDs
'Pelco D is supplied by "PTZ CONTROLLER V1.6 from:
' http://www.serialporttool.com
'First test of building block to control Pan Right.










Symbol MY_ADR = $00 ' Select Address for this PICAXE receiver

Symbol adr = b0
Symbol cmd1 = b1
Symbol cmd2 = b2
Symbol dat1 = b3
Symbol dat2 = b4
Symbol chks = b5

Symbol tmp = b6

Symbol STX = $FF

Symbol RX_PIN = 2
Symbol RX_BAUD = N4800

Do
Gosub GetPacket
If adr = MY_ADR Then
Gosub HandlePacket
End If
Loop
GetPacket:
Do
SerTxd("Waiting for packet",CR,LF)
SerIn RX_PIN,RX_BAUD,(STX),adr,cmd1,cmd2,dat1,dat2,chks
SerTxd("Got Packet",CR,LF)
tmp = adr + cmd1 + cmd2 + dat1 + dat2
if tmp <> chks Then
high 7
SerTxd("Failed chacksum",CR,LF)
End If
Loop Until tmp = chks
SerTxd("Passed checksum",CR,LF)
Return

HandlePacket:
b0 = cmd1
b1 = cmd2





outpin0 = bit9
outpin1 = bit10
outpin2 = bit11
outpin3 = bit12
outpin4 = bit13
outpin5 = bit14
outpin6 = bit15
outpin7 = bit0
pause 500
low 0,1,2,3,4,5,6,7
Return
 
Last edited:

tmack

Member
1st crack at the transmitter side

This is my first crack at the transmit side for Palco "D" . I want to make a hand held device with switches that will send RS232 in the pelco protocall to my reciever that I have built in the past that works with Pelco D:

Symbol My_ADR = $00
Symbol adr = b0
Symbol cmd1 = b1
Symbol cmd2 = b2
Symbol dat1 = b3
Symbol dat2 = b4
Symbol Chks = b5
Symbol tmp = b6
Symbol Tx_Pin = 2
Symbol Tx_baud = N4800

Do
If Pin4 = 1 Then : b3 = "4" : End If
If Pin3 = 1 Then : b3 = "3" : End If
If Pin2 = 1 Then : b3 = "2" : End If
If Pin1 = 1 Then : b3 = "1" : End If

Serout 0, N4800, (b3)
pause 100
LOOP

I am sure I am not even close but I think it is a starting point. I dont have anything there about the checksum .Any help would be greatly appreciated. Thanks, T
 

westaust55

Moderator
Not sure exactly what help you require but here goes:

Since in the receiver code you have:
SerIn RX_PIN,RX_BAUD,(STX),adr,cmd1,cmd2,dat1,dat2,chks

So for the transmitter, as a starting point you need to define a qualifier
SYMBOL STX = $FF ; same as the receiver qualifier
And the SEROUT line needs, as a starting point, to become:

SEROUT, 0, N4800, (STX, adr, b3)

You may need to add some dummy data for all fields if you are trying to accept this with your working receiver code otherwise the receiver will be out of synch.

So until you have all the commands and data worked out you could try:

SEROUT, 0, N4800, (STX, adr, b3, 0, 0, 0, b3)

Where the second b3 is the checksum so your existing receiver code see the right number of bytes and a valid checksum value.
 

hippy

Technical Support
Staff member
From the code in post #2, I'd assume ...

adr = ?
cmd1 = ?
cmd2 = ?
dat1 = ?
dat2 = ?
chks = adr + cmd1 + cmd2 + dat1 + dat2
SerOut TX_PIN, TX_BAUD, ( STX, adr, cmd1, cmd2, dat1, dat2, chks )
 

tmack

Member
How does this look?

Any thoughts on this code?



Symbol STX = $FF

Do
b3 = "0"
If pin4 = 1 Then : b3 = "??" : End If
If pin3 = 1 Then : b3 = "??" : End If
If pin2 = 1 Then : b3 = "??" : End If
If pin1 = 1 Then : b3 = "??" : End If
SerOut 0, N4800, (STX,$00,b3,0,0,0,b3)
Pause 100
Loop


Am I in the ballpark?
If so, What would I use where the ?? are in order to get my reciever (above) to work with it? As always, Thank you for any help.
 
Last edited:

tmack

Member
I tried to have b3 equal ,9,10,11,12 which is what I thought the decoder was looking for but that didnt work. Anyone have any suggestions? Thanks for any help.
 

hippy

Technical Support
Staff member
Previously you designed a Pelco D decoder so you could run the Pelco D generator into that to check it works.

As to what address, commands and data values for whatever you are sending to, we can only guess unless you tell us what it is you are sending to and preferably point us to its data sheet.
 

tmack

Member
I hooked up a serial analyzer to the info I am trying to send. There is alot I don't know (understatement I know!).

Here is what do know:
The address is set to 1
the baud rate is 4800
my "decoder " works when it receives my output from the laptop software that sends PTZ
the line my analyzer shows:(which is the Up from the PTZ)

00 FE FE FE FE 9E 06 9E 9E 00
This makes my led go high

00 FE FE FE FE 9E 06 9E 9E 06
This makes my led go low.

I guess I am looking for a simple way to output that same line above So I can begin to understand how it works so I can try to "run " from there.
I am not sure if it would be as simple as :
to make the led blink
The programmer wont except the FEs so Im at a loss:

Do
SerOut 0, N4800, (00,FE,FE,FE,FE,9E,06,9E,9E,00)
Pause 500
SerOut 0, N4800, (00,FE,FE,FE,FE,9E,06,9E,9E,06)
Pause 500
Loop
 

hippy

Technical Support
Staff member
You have to use $ to specify hexadecimal ...

SerOut 0, N4800, ($00,$FE,$FE,$FE,$FE,$9E,$06,$9E,$9E,$00)

However ... If $FF is STX according to the protocol that's not a valid packet, unless that's simply not showing the STX before a packet - but then, 'adr, cmd1, cmd2, dat1, dat2, chks' is six bytes, and it's showing 10. So that doesn't look like Pelco D, you've got the wrong baud rate, or signal polarity is inverted, or something.

It's all too confusing for me and I'm not sure exactly what is connecting to what, what does work and what doesn't, what the "analyzer" is. If I understand right you started with ...

1) Pelco D transmitter -> A something receiver

You replaced the receiver with a PICAXE and that worked ...

2) Pelco D transmitter -> PICAXE receiver

You should be able to replace the transmitter with a PICAXE and that should also work ...

3) PICAXE transmitter -> PICAXE receiver

You should also be able to use the PICAXE to control that 'something in (1) ...

4) PICAXE transmitter -> A something receiver

I don't really understand what the difficulty is or where the problem may lie. The protocol format from transmitter to receiver will remain consistent. That's defined and well documented, and we know we can handle that protocol through (2) where we receive it. It should simply be a case of generating the same protocol and the receiver won't care if it comes from a genuine Pelco D transmitter as in (1) or a PICAXE transmitter as in (3) and (4).

Even if the PICAXE receiver in (2) requires a different packet to what the PICAXE transmitter in (4) puts out, the protocol should remain consistent, only the data varies.

It may be best to approach this as ...

Pelco D transmitter -> PICAXE -> A something Receiver

The PICAXE reads and disassembles the incoming packet, re-assembles and transmits the packet on. When that works, you'll know exactly what data is in each particular packet, then the PICAXE can produce the data itself and the transmitter can be disconnected, the PICAXE replacing that transmitter.
 

tmack

Member
"However ... If $FF is STX according to the protocol that's not a valid packet, unless that's simply not showing the STX before a packet - but then, 'adr, cmd1, cmd2, dat1, dat2, chks' is six bytes, and it's showing 10. So that doesn't look like Pelco D, you've got the wrong baud rate, or signal polarity is inverted, or something."

- You were right Hippy I had the polarity inverted!
So now what I am seeing on the analyzer is more like what it should be:

($FF,$01,$00,$08,$01,$34,$3E)

When I put this code into my 18M it still just sent a bunch of 00s instead of what it should look like above.(when seen in the analyzer) and the decoder doesn't respond to it.

do
SerOut 0, N4800, ($FF,$01,$00,$08,$01,$34,$3E)
loop

Could the timing be off,too quick or something,Or might I need a capacitor somewhere? I tried it with my polarity both ways to make sure I didn't have that wrong again. Thanks for the help, Sorry Im so dense.
 

tmack

Member
Hippy,
After beating my head against the wall, trying to figure out why it is not working for another hour this morning, I swapped out my picaxe. As soon as I hooked everything back up and downloaded my code. It worked like a champ! Must have been some issue with that chip. It let me download programs into it but something somewhere wasn't right. Thanks you so much for all of your help. It was a big help in troubleshooting, knowing that it SHOULD really be working. Now I can move on to the next steps and use inputs to send out the various commands. Thanks again!
 
Top