Shiftout command


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108

    Default Shiftout command

    I have a question about the Shiftout command in PBP3. Here is the command:

    SHIFTOUT DataPin, Clockpin, Mode, [Var]

    I understand the variable is taken and the bits are shifted out one at a time through DataPin, under the timing of Clockpin. What is Clockpin? If it's the internal clock, how does one relate this parameter (Clockpin) to it? Hardwire? Softwire? Eg, on a 16F887 there is a Clockout pin (pin 14). Do I have to physically tie this to a port input for Clockpin or is there a way to access it internally?

    In examples I've seen Clockpin was equated to a port pin, eg PortA.0. In this case is PortA.0 an input to which you apply the clock?

    And finally the book says Clockpin may be a constant or a variable. I don't understand the constant bit, but for a variable does this mean I can toggle Clockpin high/low to act as an asynchronous clock?

    thanks

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Shiftout command

    Hi,
    DataPin and ClockPin are both physical pins on the device, for example PortB.2 and PortD.0.
    Since the SHIFTOUT command is bit-banged and software timed you can select any pins you wish as long as they can be made outputs.

    The clock is generated by software loops in the PIC and sent to the pin you specify as ClockPin. You can not "drive" the SHIFTOUT or SHIFTIN commands with an external clock, with these commands it's always the PIC that generetaes the clock.

    /Henrik.

  3. #3
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: Shiftout command

    So why, if the PIC is driving the clock does the Shiftout command even need that parameter? Is the port associated with it (in your example PortB.2 or PortD.0) just a "holding place" for it or is the port connected inside the PIC itself? If I scoped one of those ports would I see a clock signal? (i'm going to try it...)

    Also, how can a constant be used for ClockPin with a value of 0-15? How does THAT work?

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: Shiftout command

    Hi,
    SHIFTOUT/SHIFTIN are used for synchronous communications (unlike SEROUT/SERIN etc which are asyncrounous) which means that there one dataline and one clock line (and quite often a chip select). If you SHIFTOUT a byte variable there will be 8 pulses on the pin you specify as ClockPin. During each pulse the 8 indivdual bits of your byte variable will be present as a voltage on the DataPin. Depending on the MODE you specify with the SHIFTOUT command you can change the exact behaviour of the output ie. in which order the bits are shifted out and the "polarity" of the clock.

    Please do scope it and you'll see how it works.

    EDIT: Oh, the constant thing. That's just to be compatible with the BasicStamp2 syntax where the I/O's are labeled 0-15. Usually '0' is PortB.0 but it might differ depending on the actual PIC you're compiling for. Best is to just forget about that and use PortB.3 etc.
    Last edited by HenrikOlsson; - 16th January 2012 at 17:50.

  5. #5
    Join Date
    Jun 2011
    Location
    Indian Harbour Nova Scotia
    Posts
    108


    Did you find this post helpful? Yes | No

    Default Re: Shiftout command

    Thanks Henrik. That does clear somestuff up. I put a logic probe on the pins and sure enough they do what you say they do. I was making it more complicated than it actually was. I do have the portion running with the Shiftout command, looks so SIMPLE now!

    BTW Congratulations Sweden on beating the Russians and winning GOLD in the Junior World Hockey championship.

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts