serout out of order on 12F675


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Angry serout out of order on 12F675

    IŽm trying to send data from PIC to BS2 via serout2 but the values are sistematically been altered.

    The 12F675 is generating the sequence:
    0,1,2,3,4,...,255

    And the BS2 is receiving:
    128,129,130,131, ... , 157,158,159,128, 129,130,...

    I verified and OSCCAL was not erased.
    Things got better when i include the line:

    Define OSCCAL_1K 1

    on the code, but the problem did not dissapear at all.

    here are the codes:

    12F675 code:
    Code:
    include "bs2defs.bas"
    Define OSCCAL_1K 1 ' Set OSCCAL for 1K Device
    
    ANSEL=%00000000
    CMCON=%00000111
    
    Trisio = %11111111 ' Set all ports as inputs
    Trisio.4 = 0 ' Set port GP4 as output
    
            saida    CON 4     
     
            i var byte
           
            pause 1000
    loop:
            for i = 0 to 255
                 serout2 saida,16780,[i]
                 pause 100
            next
    
            pause 2000
            goto loop
            end
    The BS2 code:
    Code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    entr      PIN  1
    entr_mode  CON  16780   'entrada baudmode = 2400/8N1 INV
    PAUSE 10
    
    p VAR Byte
    
    Start:
    SERIN entr,entr_mode,[p]
    DEBUG DEC p,"  "
    GOTO Inicio
    Seems to me that is some timing problem. I overnight on this problem without a solution. I must be missing something trivial, but I cant figure out what!

    IŽll appreciate any help
    Last edited by Ricardo; - 28th April 2008 at 04:38. Reason: I made a mistake on first typing

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    What happen if you place
    Code:
    GPIO=0
    just before the PAUSE 1000?

    Did you tried to connect your PIC directly to your PC?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Apr 2008
    Posts
    5

    Smile

    Thank you for your comment, I will try your suggestion. Just a note: the code works fine on an 16F688 using the same I/O pin GP4.(with minors modifications: TRISIO replaced by TRISA, ANSEL replaced by ADCON1, CMCON line removed)

  4. #4
    Join Date
    Apr 2008
    Posts
    5

    Exclamation Same code worked on a 16F688

    Thank you for your comment, I will try your suggestion. Just a note: the code works fine on a 16F688 using the same I/O pin GP4.(with minors modifications: TRISIO replaced by TRISA, ANSEL replaced by ADCON1, CMCON line removed). I didn't try to connect directly to my PC.

  5. #5
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Smile

    Serout2 sends LSB first – your HSB appears to be the one that is corrupted. This screams “timing issue” to me. If you are using the Internal Oscillator (which it appears you are), you might want to switch to a XTAL for reliable timing. If that is not possible, consider a slower baud rate or get a good scope and play with the OSCAL value until the timing works (at the given temperature – it will change if the temperature changes).
    HTH,
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  6. #6
    Join Date
    Apr 2008
    Posts
    5

    Default Problem solved!

    Paul,

    Based on your comment, I assumed that the pic basic was reading the stop bit as the MSB of the data. My conclusion is that the pic clock was too fast. So I reduced the OSCCAL from its 3460h original value to 3450h and it worked on the first try! Now IŽll play a litle bit more with the OSCCAL to find the midpoint to (hopefully) garantee that the circuit will be stable over temperature changes.

    Thank you for your valuable help!

  7. #7
    Join Date
    Apr 2008
    Posts
    5

    Default DidnŽt work

    Quote Originally Posted by mister_e View Post
    What happen if you place
    Code:
    GPIO=0
    just before the PAUSE 1000?

    Did you tried to connect your PIC directly to your PC?
    Putting GPIO=0 have no effects on the output, but I can learn on the process. What is the purpose of this line?

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Default

    >> Putting GPIO=0 have no effects on the output, but I can learn on the process. What is the purpose of this line?

    Mister-E wanted to make sure you were idling low, which is good practice.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. 12f675 Serout Int_Osc problem
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th April 2007, 09:39
  5. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26

Members who have read this thread : 1

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