18F24J11 clock and HSER/HSER2 baud rates


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Default 18F24J11 clock and HSER/HSER2 baud rates

    The following code runs as a LED blinker (1 sec. per cycle) with a character sent to both HSER and HSER2 ports at 115200 each time through the loop. Note the 'WHY??' comments in the code as to what happens when various DEFINES are used. Also the timing loop needs 3333 count to make one second interval. Also the OSC define does not seem to work.
    Using MicroCodeStudioPlus v3.0.0.5 Complier is PICBASICPRO 2.60L and MPLabIDE is v8.56
    I would really appreciate any suggestions....Brian

    Code:
    '****************************************************************
    'CONFIG BITS ON PICKit2 set to 04A1 09DC 09FF 01CF
    
    ;DEFINE OSC 40            ' enable this and HSER2 baud rate is around 14400
                        ' and pause loop becomes 5 sec on 5 sec off not 1/2 sec
                        ' Why does DEFINE OSC not work?
    DEFINE HSER_RCSTA 90h   ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h   ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 1Ch   ' SPBRG with no H                WHY???
    DEFINE HSER_CLROERR 1   ' Clear overflow automatically  
                                            ' Why no BAUD rate define needed ??
    DEFINE HSER2_RCSTA 90h  ' Enable serial port & continuous receive
    DEFINE HSER2_TXSTA 24h  ' Enable transmit, BRGH = 1
    DEFINE HSER2_SPBRGH 1Ch ' SPBRG with H                    WHY???
    DEFINE HSER2_baud 38400  ' only value that yeilds 115200   WHY??? 
                         ' without this DEFINE baud rate is 9600
    DEFINE HSER2_CLROERR 1  ' Clear overflow automatically
    BAUDCON.3 = 1                  ' Enable 16 bit baudrate generator
    
    char    VAR    BYTE
    CLRWDT                                           
    INTCON     = 0
    INTCON2    = 0
    INTCON3    = 0
    TRISA     = %00000000
    TRISB    = %00000000     'PORTB.5 is out TO led
    TRISC    = %10100000     'HSER ins on bit5,bit7 and outs on bit4,bit6
    
    ;asm code to set HSER2 I/O pins right from microchip data sheet
    asm                     
        MOVLB     0x0E  
        MOVLW     0x55
        MOVWF    EECON2, 0
        MOVLW     0xAA
        MOVWF    EECON2, 0
        BCF     PPSCON, IOLOCK, BANKED
    endasm
    asm
        MOVLW     0x10
        MOVWF     RPINR16, BANKED        ;HSER2 input on RP16
    endasm
    asm
        MOVLW     0x05
        MOVWF     RPOR15, BANKED      ;HSER2 out on RP15
    endasm
    asm
        MOVLW     0x55
        MOVWF     EECON2, 0
        MOVLW     0xAA
        MOVWF     EECON2, 0
        BSF     PPSCON, IOLOCK, BANKED
    endasm
    
    char = 65
    LUPE:    high porta.5          ' Flash an LED on PORTa.5 at 1 sec. cycle
            PAUSE 1666            ' this gives 1/2 sec pause    WHY???
            low porta.5
            PAUSE 1667            ' this gives 1/2 sec pause    WHY???
            IF char = 65 THEN HSEROUT  ["HSER 115200 Baud",10,13]        
            HSEROUT [char]        
            IF char = 65 THEN HSEROUT2 ["HSER2 115200 Baud",10,13]        
            HSEROUT2 [char]    
                
            char = char +1     'Output ascii characters from 'A' to '}'
            IF char = 126 THEN char = 65 
            GOTO LUPE
    
    '------------------------------------- 
         END
    Last edited by ScaleRobotics; - 17th September 2010 at 18:32. Reason: added code tags

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    What kind of crystal are you using? You have your OSC set to HS, with no PLL. The biggest crystal you can put on it is 20 mhz.
    http://www.scalerobotics.com

  3. #3
    Join Date
    Mar 2009
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    The Crystal is a CM-309S 40 MHz and a scope shows it oscillating correctly at 40 MHz.
    The 'CONFIG BITS ON PICKit2 set to 04A1 09DC 09FF 01CF indicates that bits 0-2 of 09DC are set to HS mode and the HSER outputs are indeed 112500 baud.
    The timing PAUSE instruction needs 3333 count to create 1 second delay which seems to suggest an instruction clock of 13.3 MHz.
    4 MHZ PAUSE instruction delays 1 msec, ie PAUSE 1000 = 1 sec.
    I have to use PAUSE 3333 to yield1 sec. thus internal clock seems to be 13.2 MHZ.

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