16F648 and 115200 at 4 Mhz doesn't work...


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2007
    Posts
    39

    Default 16F648 and 115200 at 4 Mhz doesn't work...

    Hello,
    I stared to be frustrated from the fact, that my 16F648 doesn't work at 4 Mhz clock speed with HSERIN/HSEROUT commands.
    Please see this code:

    DEFINE OSC 20
    'hserin definition
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 115200
    DEFINE HSER_CLROERR 1

    while 1
    if (PIR1.5==1) then
    goSUB manageSerialByte
    endif
    wend
    end

    manageSerialByte:
    HSERIN 1,Jump,[SERIALBYTE]

    If SERIALBYTE = "p" Then
    HSEROUT ["hello",10]
    end if
    Jump:
    return

    This code is working perfectly, please see that OSC is 20 and I am using 20Mhz crystal resonator.

    But due to the fact, that I want to operate the circuit on 3V, I need to use 4Mhz crystal and OSC 4.

    So only what I did in my code I changed the first line:
    DEFINE OSC 4

    But I cannot manage to make serin and serout working. And the controller is working, because I am using in the code tmr0 interrupt, which is blinking LED and the LED is blinking, it means, that the PIC is working and processing the code, but the problem is, that this SERIN/SEROUT simply not work!!!
    Thanks for feedback, what do you think about this strange problem...

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    While the USART can go that fast at 4mhz, the closest to 115,200 you can get is 125,000, which is an 8.5% error.

    If you use a 3.579mhz colorburst crystal. You can get 111,243 baud which is only 2.9% error.

    Also there are a couple problems in your code. They may just be typo's, but...

    The SERIALBYTE variable is missing. and...
    just before JUMP: the "END IF" should be ENDIF.

    HTH,
    DT

  3. #3
    Join Date
    Jan 2007
    Posts
    39

    Default

    Cus Darrel,
    OK, thanks for the answer. These typo is OK, I have just copy paste the parts of my code to get the idea to the others, what I am doing )))) So what you wrote is, that it is not possible to use this PIC at 4 Mhz with 115200. So you are suggesting to change tje crystal and to use 3.579 Mhz crystal, and in that case, it should work? I am now wondering, what will happen with PIC basic, because this is I think not supported. In manual for PIC basic is written that only supported values are 4, 8, 20 Mhz. Am I right? If not, what should be the OSC?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    OSC 3 is for 3.579mhz. (PBP manual page 170)

    All the timing (pauses etc.) should work fine.

    DT

  5. #5
    Join Date
    Jan 2007
    Posts
    39

    Default Working

    Hello, I've just returned from holiday. I've just tested the 3 Mhz crystal and it is working well. So thanks a lot for valueable hints and answers!!!

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    Excellent!

    That's the first time I've seen a need to use OSC 3.
    I always wondered why it was an option. Now we know.

    Regards,
    DT

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