Shop OBEX P1 Docs P2 Docs Learn Events
Prop1 RS-485 COMM using SN75176 to send Pelco commands — Parallax Forums

Prop1 RS-485 COMM using SN75176 to send Pelco commands

FalconFalcon Posts: 191
edited 2013-05-11 18:59 in Propeller 1
I'm attempting to use a Propeller to control the zoom function of a Pelco-D camera via an RC radio. My code is based on Duane Degn's RcReceiver6Demo121116a Object. I have the Prop1 reading and displaying the pulsewidth correctly. The CASE command is used to increase the speed of the zoom the further the joystick is moved from the (center) deadzone. This changes the zoom direction and zoom speed bytes.

I will use a SN75176 Differential Bus Transceiver chip between the Prop1 and the camera per this document: rs485Communication.pdf

I previously got this working with a PIC 12F683 using a SEROUT command, but now want to use the Prop1. The PIC used one pin to enable/disable communication, and one pin to transmit the data to the SN75176.

For the Prop1, I have the following circuit connections

SN75176 pin 6 to camera RS485+
SN75176 pin 7 to camera RS485-
SN75176 pins 2&3 to Prop1 pin 0 (enable/disable)
SN75176 pins 1&4 to Prop1 pin 1 (transmit)

Each Pelco command requires I send 7 bytes of hex data that includes a checksum. Example: Camera on = $FF,$02,$88,$00,$00,$00,$8A I have figured out all of the 7 byte commands so I don't have to do real-time checksum calculations.

The camera requires 2400 baud, No parity, true format.

I cannot get any response from the camera with the Prop1. I've tried the following code (using the FDS Object) but I'm not sure how to set the fds.start mode parameter.
RC_to_PELCO_Converter5_May_2013 - Archive [Date 2013.05.05 Time 18.04].zip



I also looked at the BS2_Functions Objec SEROUT Method but I'm not sure if I should use the SEROUT_CHAR Method or the SEROUT_STR Method to send 7 bytes.

Can anyone provide an example of a way to send those 7 byte commands.

falcon

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-05-05 16:30
    Falcon wrote: »
    SN75176 pins 2&3 to Prop1 pin 0 (enable/disable)
    SN75176 pins 1&4 to Prop1 pin 1 (transmit)
    Your code starts FDS on pins 0 (rx) and 1 (tx). IOW pin 0 is an input and therefore unsuitable to drive the enable/disable pair. Try relocating this pin (for FDS) and use pin 0 as an output set to the appropriate value(s).
  • JonnyMacJonnyMac Posts: 8,912
    edited 2013-05-06 20:57
    If you're using half-duplex serial you need to be able to enable and disable the transmit mode of the chip appropriately. I wrote my own object to do this -- see attached. The object also controls an [optional] LED so you can see when the Propeller is transmitting versus receiving.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-05-06 22:43
    Just out of curiosity, is there a reason you are controlling the PTZ this way as opposed to a computer or DVR with Keyboard/Joystick? I have several Pelco Spectra II and Spectra III cameras and if there is a better way to control them I would love to do it. I currently have mine controlled via Comm ports on my computer and my software enables me to use the PTZ features.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-05-07 00:34
    NWCCTV wrote: »
    Just out of curiosity, is there a reason you are controlling the PTZ this way as opposed to a computer or DVR with Keyboard/Joystick? I have several Pelco Spectra II and Spectra III cameras and if there is a better way to control them I would love to do it. I currently have mine controlled via Comm ports on my computer and my software enables me to use the PTZ features.

    I run PTZ cameras from the Prop using a standard PS2/USB keypad. The reason is that I normally only need preset positions and zoom so it's easy to run this from the Prop plus it's being used for other things anyway. I can also enter a manual mode where I use the keypad to manually PTZ with accelerating key functions the more I press the same key. The manual mode is used to initially setup the camera's preset positions after which it becomes a simple [CAM] + [0..9] to go to the presets.
  • FalconFalcon Posts: 191
    edited 2013-05-07 04:21
    The Camera is mounted on a rover and uses a slipring to allow 360 deg rotation. Pan and tilt are controlled by continuous rotation servos The camera uses the Pelco-D format via RS-485 so I want to control the zoom with the RC(PWM) to PELCO-D converter.

    I have several PTZ cameras in my home security system and use either a stand-alone hard-wired controller, DVR commands or an IR controller, depending on the situation.

    falcon.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-05-07 14:51
    It looks as though we are getting double posts again.
  • FalconFalcon Posts: 191
    edited 2013-05-07 17:31
    Well...JonnyMac comes through again. You can bet if an Object starts with "jm", it will help with your project.

    I now have communication with the camera. I'm using the SN75176 I have on hand vs. the MAX485, but it works.

    Duane Degn's RcReceiver6Demo121116a Object works like a charm in reading the RC Receiver and displaying the pulselength.

    The one last problem I have is getting the pulselength to control which block of code is sent to the camera. I changed the code to control the Pan function since it's easier to see a result. The zoom is an internal (but optical) movement.

    My approach is to use a CASE statement. The joystick center is around 1500 uS. I'll add a deadband for hysteresis when I go back to the Zoom code. Below 1500 uS the Prop1 would send the block of code to Pan Right. Above 1500 uS the Prop1 would send the block of code to Pan Left I thought I had the CASE statement formatted like the Prop Manual but I don't get any movement. I did move the following line of code to the end. The pulselength is displayed on the PST.
     previousPulseLength[0] := pulseLength[0]
    

    I figured the CASE statement needed to see the pulselength before it is reset. I hope I'm right there.

    So, did I get the CASE statement wrong?

    Is there a better way? When I revert back to the Zoom function I will break the pulselength range into 8 zones and adjust the zoom speed based on joystick displacement.

    Latest code:
    RC_to_PELCO_Converter_7_May_2013 - Archive [Date 2013.05.07 Time 18.59].zip


    falcon
  • JonnyMacJonnyMac Posts: 8,912
    edited 2013-05-07 21:45
    Well...JonnyMac comes through again. You can bet if an Object starts with "jm", it will help with your project.

    I rule! ;)

    You may be having a problem with the code in that you are checking to see if the current reading is the same as the last -- but with a joystick and a possible range of 1000 to 2000 there could be some wiggle. Figure out what your input range is and then divide that by the number of zones you want to handle. For starters, use 3 (left, stop, right). If the receiver is giving you 1000 to 2000 you might do something like this:
    last := -1
    
      t := cnt
      repeat
        zone := rc.get(0) / (1000 / 3)
        if (zone <> last)
          case zone
            0:
            ' pan left code
    
            1:
            ' stop camera movement
    
            2:
            ' pan right code
    
          last := zone  
        
        waitcnt(t += (clkfreq / 10))
    
  • FalconFalcon Posts: 191
    edited 2013-05-11 18:59
    Thanks JonnyMac.

    That worked like a charm.

    I will want a smaller "dead" zone so I think I can use something like:
     last := -1
    
      t := cnt
      repeat
        zone := rc.get(0) / (1000 / 15)
        if (zone <> last)
          case zone
            1:
            ' pan left fast code
            2-4:
            ' pan left medium code
            5-7:
            ' pan left slow code
    
            8:
            ' stop camera movement
    
            9-11:
            ' pan right slow code
            12-14:
            ' pan right medium code
            15:
            ' pan right code
    
          last := zone  
        
        waitcnt(t += (clkfreq / 10))
    
    I appreciate your, and everyone's, help.

    falcon
Sign In or Register to comment.