Serin usage?


Closed Thread
Results 1 to 15 of 15

Thread: Serin usage?

Hybrid View

  1. #1
    Join Date
    Nov 2006
    Posts
    32

    Default Serin usage?

    Hi all!
    I'm having some trouble/fun trying to communicate serially with a PIC16F627. I am using an optical (quadrature) encoder, with a quadrature decoder w/ a built in counter. The counter will count the up/down pulses, and hold them in a shift register where they can be read serially (in 22 bits). I want to be able to have the PIC read the serial data (as many bits as possible {8?}) and display it on an LCD. Should I be using the SERIN function? If so, how do I make sure that the bits that are read into the PIC start with the LSB of what the counter has in it's shift register? Also, I need a little help with selecting the baud rate. I have included a snippit of the code I am using as well as a brief explanation of how the counter's shift register works.

    Code:

    loop:

    high plsr
    low Plsr
    low Cs
    serin cntdata,4,total
    pause 22
    high cs
    LCDout $FE, 1, "position", $FE, $C0, BIN total
    Pause 1000

    goto loop

    Counter Shift Register Link:

    http://www.genapta.com/WORD%20DOCS/A...nterfacing.pdf

    Thanks a lot for all of your help, and any input would also be appreciated. As soon as this all works I have been working on a writeup that I will post on the forumn for all of those first time encoder users like me.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by champion View Post
    Hi all!
    I'm having some trouble/fun trying to communicate serially with a PIC16F627. I am using an optical (quadrature) encoder, with a quadrature decoder w/ a built in counter. The counter will count the up/down pulses, and hold them in a shift register where they can be read serially (in 22 bits). I want to be able to have the PIC read the serial data (as many bits as possible {8?}) and display it on an LCD. Should I be using the SERIN function? If so, how do I make sure that the bits that are read into the PIC start with the LSB of what the counter has in it's shift register? Also, I need a little help with selecting the baud rate. I have included a snippit of the code I am using as well as a brief explanation of how the counter's shift register works.

    Thanks a lot for all of your help, and any input would also be appreciated. As soon as this all works I have been working on a writeup that I will post on the forumn for all of those first time encoder users like me.
    Why even bother with the decoder/counter chip. The PIC has plenty of processing power to keep an eye on a few quad-encoders and do serial input/output at practically the same time. If I can do an mp3 player on a PIC16F877, with IR, hard drive, battery monitor, keypad monitor, LCD output, USB connection (thru an FTDI245AM), and a few other things, you can certainly count pulses from a few quad-encoders...

    It's kinda like having english as your first language, but also knowing how to speak spanish, and then talking to a spanish-speaking person thru a spanish-english translator. It's like one extra middle-man (or middle chip in this case) that isn't really needed.

  3. #3
    Join Date
    Nov 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    I need an extremely high resolution. My encoder has 8192 pulses per revolution, however I need to be able to see a 1 minute change in angular position. This means that i need 360*60=21600 pulses per revolution. Thus with a quadrature decoder I can get 8192*4=32768 pulses per rev. Believe me, after all of this trouble, I would much rather do without the decoder, as I feel more comfortable with the PIC by itself.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by champion View Post
    I need an extremely high resolution. My encoder has 8192 pulses per revolution, however I need to be able to see a 1 minute change in angular position. This means that i need 360*60=21600 pulses per revolution. Thus with a quadrature decoder I can get 8192*4=32768 pulses per rev. Believe me, after all of this trouble, I would much rather do without the decoder, as I feel more comfortable with the PIC by itself.
    An 18F series PIC can run 40mhz, 10MFlops... you don't think that's fast enough to catch 21,600 pulses per rev?
    If I can transfer 1MB/sec thru USB, do 2.5mbps on a serial line, mirror a hard drive with a custom interface at about 5MB/sec, you can surely read an encoder that fast.

  5. #5
    Join Date
    Nov 2006
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Skimask, we get it. You know what you're doing with a PIC, but it's not helping anyone to brag about what you can do or have done. This site is about helping people work out their issues with projects relating to the PIC and MELabs stuff. If you have a suggestion, please let me and the others know. But just bragging is a little lame. Also, my issue has to deal with the output of the encoder not generating enough ppr to have the kind of revolution that I need, thus requiring a quadrature decoder to increase the ppr of the encoder. I have no doubt that the PIC will be able to handle the pulses after that. The thing I can't figure out now is how to interface the decoder with the PIC from the PicBasic code side. Thanks for your help and I hope someone has an idea as to what I could try as far as the code to implement this contraption goes.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,607


    Did you find this post helpful? Yes | No

    Default

    Hi Champion,
    That IC uses a synchronous serial interface so SERIN will not work. I think you need to have a look at the SHIFTIN command instead. I'm not sure if it can shift in all 22bits in one shot but perhaps it can. It can definetly read the lower 16bits in one go - perhaps that's enough for you.

    Code:
    Counter VAR WORD
    
    LOW CS		'Select chip
    HIGH PLSR	'Load counter to shift register
    
    'Shift in 16bits of data. you may need to experiment with the mode number.
    Shiftin CNTdata, CLKsr, 3, [Counter\16]
    Low PLSR
    High CS		'Deselct chip.
    
    'Display or whatever.
    The datasheets indicates that the PLSR needs to be held high while reading the first bit so I guess it CAN be held high while reading the rest too since the shift register is loaded on the rising of PLSR going high. You'll have to experiment there.

    Try to get it to read the lower 16bits first, then we can figure out a way to read all 22. I think that the tricky part will be what to to with the 22bits when you have them in the PIC.

    /Henrik Olsson.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by champion View Post
    Skimask, we get it. You know what you're doing with a PIC, but it's not helping anyone to brag about what you can do or have done. This site is about helping people work out their issues with projects relating to the PIC and MELabs stuff. If you have a suggestion, please let me and the others know. But just bragging is a little lame. Also, my issue has to deal with the output of the encoder not generating enough ppr to have the kind of revolution that I need, thus requiring a quadrature decoder to increase the ppr of the encoder. I have no doubt that the PIC will be able to handle the pulses after that. The thing I can't figure out now is how to interface the decoder with the PIC from the PicBasic code side. Thanks for your help and I hope someone has an idea as to what I could try as far as the code to implement this contraption goes.
    >Skimask, we get it.
    We may get it, but you apparently haven't yet...
    And I ain't braggin' 'bout squat... I haven't done anything miraculous or extraordinary or anything new and fantastic that anybody else has already done a dozen times. So...WAAAAAAAAAHHHHHHH!!!!

    So, be that as it may, if you are having trouble with the decoder, get rid of it. IF you can make a PIC do the work of this optical encoder, and IF you can figure out how to transmit data between 2 PICs, then MAYBE, just MAYBE you could set up one PIC running at high speed doing nothing but reading the optical encoder and POSSIBLY send that data to another PIC to do work for you instead of a single PIC handling everything (which again, shouldn't be a problem in the first place). But with 2 PICs, you'd be splitting up the tasks into managable chunks.

    And I'm out....

Similar Threads

  1. Accurate serin usage?
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th July 2009, 08:36
  2. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  3. serin question?
    By sachymo in forum General
    Replies: 5
    Last Post: - 27th July 2008, 10:04
  4. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 0

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

Posting Permissions

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