1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Electronics Encoder Handler - Need some help

Discussion in 'Modding' started by Gambler, 1 Sep 2007.

  1. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Ok everyone...I have officially bit off more than I can chew! Hooah!

    So anyway, I have purchased a 40 pin microcontroller (16F877A) along with a nice little dev board for it (here). I got this particular board, because I want to be able to communicate with the chip over a serial cable. Here is the setup:

    I already have a working (robot) controller, it has a serial port that I can easily access.
    I want to plug the little dev board into that serial and be able to communicate between the chips.
    The encoder handler half with have 8 encoders hooked up to it (they will be turning slow, don't worry) and will be logging clicks.
    I want to transmit the value of each encoder count over the serial port.

    So then, to what pins do I attach the "TX, RX, CTS, and RTS" pins on the dev board to?
    Do I need to write in some bit-banging or does the chip I have have hardware com control?

    I'm a semi-noob to microcontrollers, I typically just program them, so I am good in that regard, just need some hardware help.

    Thanks!
    -Gambler
     
    Last edited: 1 Sep 2007
  2. const_

    const_ What's a Dremel?

    Joined:
    15 Nov 2005
    Posts:
    121
    Likes Received:
    1
    from what i can read off microchip website the chip has built in support for USART,so there is no need to bit bang.

    Tx (pin 25) goes to the receive pin of the max232 chip which is pin 10
    Rx (pin 26) goes to the transmit pin of the max232 chip which is pin 12

    i never used the CTS RTS pins, a strange dev board you got there

    max232 has 2 Rx,Tx modules somehow the dev board is using the second module for CTS,RTS. you should be fine not connecting them anyways.
     
  3. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    The MAX232 is designed exactly for that purpose const_, so that you have Rx, Tx, CTS and RTS at the correct levels.

    It depends on your application if you want to use CTS and RTS, but on that particular PIC, you'll need to check those in software (which is very simple). Then just use the built in USART on RC6 and RC7 for Tx and Rx.
     
  4. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    I have never used CTS or RTS in any of my previous serial applications (unless the guy who designs hardware put it in there, which I doubt). So unless using the handshake is better, I think I will avoid it.

    Anyone know of a library reference for this particular chip? Im using MPLAB.

    Thanks for the info! No doubt I will be asking for more.

    Thanks!
    -Gam
     
  5. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    The obvious advantages of hardware handshake are apparent when high data throughput is required. Blindly firing data at the serial port would overrun the buffer at either end meaning your whole frame may end up getting resent depending on how big of a packet your CRC or Checksum was covering.
     
  6. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Fair. So then do I just have to sacrifice a couple I/Os for use as CTS/RTS?
     
  7. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    If your application needs it, then yeah, any will do, just check one before sending and assert the other if you're unable to receive any more data while you're processing it.
     
  8. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Ok,

    So I have the max 232 hooked up, just need to get my programmer working before I start soldering.

    Now my next question. The datasheet says that there are 15 available interrupt channels on the pic, but I have no idea which ones. I am assuming, since it doesnt actually call any of the pins interrupts, that I simply cant have more than 15 pins enabled as interrupts. Is that true, or are there only 15 pins that can handle interrupts?

    Thanks!
     
  9. ConKbot of Doom

    ConKbot of Doom Minimodder

    Joined:
    2 Jul 2003
    Posts:
    2,160
    Likes Received:
    6
    no, less then that that, there may be 15 interups in total, but that includes internal hardware interupts. (watchdog timer, A/D converter interupts, 3 timer interupts, etc...) Port B, pin 0 is typically an interupt pin, but if you are just doing a few encoders, at low rates, I would imagine the best/easiest thing would be to poll the encoders, rather then using interupts, since thats the microcontrollers only job.


    If your host device (the robot) supports using CTS/RTS (some may not, might be just a RX and TX) then it makes it fairly simple for you. Have the uC keep track of the movement of each encoder, when CTS is asserted, make up a packet and send it, and reset the encoder counts, that way the encoder controller is basically telling the master "ok this encoder moved x counts in the positive direction since the last time you asked"
     
  10. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Thats nice, but hardly answers my question. Do I then have 1 interrupt pin? I have been scrounging for a schematic that includes that, but I have found nothing.
     
  11. SteveyG

    SteveyG Electromodder

    Joined:
    23 Nov 2002
    Posts:
    3,049
    Likes Received:
    8
    The external interrupt pins will be labelled INTx, probably on PORTB. The 15 interrupts are the total interrupts on the PIC, not external interrupts.

    Edit: See DS39582B-page 44 and page 45. Only RB0 is an external interrupt. RB<4:7> are IOC.
     
  12. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Ok...damn...thanks...gah!

    Time to redesign...

    I am going to assume that the encoders will be moving slow enough to just get polled. That does the job of both simplifying and compicating everything. Thanks, hopefully I will be back with a working proto by next post.
     
  13. Gambler

    Gambler What's a Dremel?

    Joined:
    16 Jun 2006
    Posts:
    90
    Likes Received:
    0
    Ok, hardware is ready to go...but:

    I cannot get MPLAB to gel with my programmer. I got a PICSTART Plus look-alike from sparkfun:
    http://www.sparkfun.com/commerce/product_info.php?products_id=3

    But when I got to "Enable Controller" I get a serial timeout error. I am using an appropriate power supply and a functional cable, any ideas? I have no other computer to try things out on for a while. But come wednesday I will be able to know if is the cable or comp for sure.

    -Gam
     

Share This Page