serial data ideas please


Closed Thread
Results 1 to 22 of 22

Hybrid View

  1. #1

    Default serial data ideas please

    I'm monitoring two lots of serial data using a 8mhz 16F886

    The first lot 9600,8,N,1 is sent automatically by an external device and by using the USART and DT interrupt driven buffer I can capture that data and send it out of the USART again nicely. This must continue in the background and it works well.

    Now I have some other 10400,8,N,1 serial data on another line coming into a normal pin so I'm limited to the serin/serin2/debugin commands. This data only appears on the line in response to a command I send out.

    I can send the command using serout2 and a for/next loop to send the packet byte by byte disabling the interrupt whilst each byte is sent, and servicing the interrupt between bytes. That works fine and the main data is still OK.

    Now I have tried recieving the response packet using serin2 and a for next loop and disabling the interrupt response whilst each byte arrives. But as i service the interrupt inbetween bytes the data is arriving too fast for the serin2 to keep up and after about two bytes it is corrupted as you can see the bits getting further to the left.

    There isnt much time between the incoming bytes for this new data and if i don't service the background interrupt for the other data between bytes then the usart overflows. Hmm?

    I can't crank up the clock speed on the 16F886 as it running on the int clock on a pcb

    I could substitue a 18F2620 which i have tried but I haven't got the clock speed/usart settings or anything right with that :?
    It worked at 8mhz but not at 32mhz.
    I did set the osc define to 32.

    Just after general brilliant ideas.

    I did try debug in that was fractionally better but corrupt after three bytes instead of two.

  2. #2
    Join Date
    Jul 2003
    Location
    USA - Arizona
    Posts
    156


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    A few ideas perhaps...
    I could substitue a 18F2620 which i have tried but I haven't got the clock speed/usart settings or anything right with that :?
    It worked at 8mhz but not at 32MHz.
    I did set the osc define to 32.
    I believe you need to specify the PLL as active to get 32MHz from the 8MHz (which I think is what your trying to use).

    I'm guessing you have something like this:
    Code:
    Main Loop:
     loop doing SERIN stuff
    
    Interrupt Service:
     Service HW USART for receive data, and re-send
    Perhaps you can create a ring buffer, and every time the HW-UART interrupt fires save the the data. The main loop would then look like.
    Code:
    Main Loop:
     Disable HW-USART interrupt
     Check HW-UART TX buffer is empty
     If empty, send next ring buffer data through HW-UART (you will do this writing directly to the TXREG and not using HSEROUT)
     Do SERIN stuff
     Enable HW-USART interrupt (for receive only)
    Interrupt service would then look like:
    Code:
    Interrupt Service:
     Service HW USART for receive only (store in ring buffer)

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    use DT int for the 104K serial on HWusart TX/RX and do the 9K serial in basic ???

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    Thanks for the ideas.

    Amgen sadly the hardware is from an old project the 10.4K serial is fixed on normal pins and the 9.6k continious data is on the usart.

    Languer at the moment when the RX INT fires my routine gets the incomming byte and fires it straight out of the USART TX, it then checks in case a second byte has arrived (Two tend to arrive together) and repeats the above if it has. Then it returns and by that time has missed a byte on the other serial in data.

    My INT Handler looks like this.

    Code:
    '-------------------------------------
    ' INTERUPT HANDLER
    '-------------------------------------
            
    INT_Serin:                                      'Serial Interrupt routine
    
        IF OERR Then usart_error                 'Check for USART errors
        ptr_in = (ptr_in + 1)                       'Increment ptr_in pointer (0 to 48)
        IF ptr_in > (BufMax-1) Then ptr_in = 0             'Reset pointer if outside of buffer
        IF ptr_in = ptr_out Then Buffer_Error            'Check for buffer overrun
        HSerin [buffer[ptr_in]]                     'Read USART and store data in next empty location
        ptr_out = (ptr_out + 1)                         'Increment ptr_out pointer (0 to 48)                          
        IF ptr_out > (BufMax-1) Then ptr_out = 0              'Reset pointer if outside of buffer 
        bufchar = buffer[ptr_out]                       'Read buffer location
        HSEROUT [BufChar]                       'Send the character
        Toggle RedLed                               'Flash the Red Led
        IF RCIF Then INT_Serin                     'Check for another character while we're here
    
    @ INT_RETURN                                   ;Return to program

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    Just trying the 18F2620 chip at 8mhz it works as expected. Lags behind after a few characters etc. But otherwise fine.

    But at 32mhz with PLL enabled the usart seems to have gone from outputing data at 9600 to 2400 according to my logic analyser :?

    If anything i would have expected it to go to 38400 not the other way round. I'm obviously missing a gothca somewhere.

    Code:
    #CONFIG
     __CONFIG _CONFIG1H, _OSC_INTIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
     __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L
     __CONFIG _CONFIG2H, _WDT_OFF_2H
     __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
     __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    #ENDCONFIG
    
    DEFINE OSC 32            'Set PicBasic Pro processor speed to 32 Mhz   
    OSCCON = %01110110         'Internal 8 mhz Osc and stable 
    OSCTUNE= %01000000        'Pllen Frequency Multiplier Enabled for 8mhz Clock enables 32mhz Clock!!
    
    CMCON  = %00000111        'Comparators Off
    CVRCON = %00000000        'CvRef Powered Down 
    
    CCP1CON= %00001100        'CCP1 Module PWM Mode
    CCP2CON= %00000000        'CCP2 Module Disabled 
    
    HLVDCON= %00000000        'HLVCON Disabled
    
    T1CON  = %00110000        '$30 = Prescaler 1:8, TMR1 OFF
        
    TRISA = %00001011         'SET PORTA0, A1 & A3 AS INPUTS, REST AS OUTPUTS
    TRISB = %00000000         'SET PORTB AS OUTPUTS
    TRISC = %10010000         'SET PORTC AS OUTPUTS EXCEPT PORT C4 & C7 
        
    ADCON0 = %00000001        'SETUP ADC & ENABLE ADC MODULE on AN0
    ADCON1 = %00001110        'SETUP ADC SET REFV to VDD & VSS AN0 
    ADCON2 = %00100010        'SETUP ADC FOSC/32 LEFT JUSTIFY TAD 8
    Any ideas?

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    Just checked and a pause is taking 4 x longer than before so looks like pbpro has compensated but that the pic is still stuck at 8mhz :?

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    Hi,
    Do you have to echo the char from within the ISR? Perhaps you could set a flag indicating that there is data to send and then do the sending a out_ptr handling in the main routine. That way you'll spend less time in the ISR. Changing:
    Code:
    bufchar = buffer[ptr_out]               'Read buffer location
    HSEROUT [BufChar]                       'Send the character
    to
    Code:
    HSEROUT [buffer[ptr_Out]]
    Might also save a couple of cycles.

    However, I think the main culprit is the saving/restoring of the system variables when entering and exiting the ISR (which DT-INTS does for you). You should be able to run the 18F2620 at 32Mhz by enabling the PLL as languer says.

    Just thinking out loud.....

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: serial data ideas please

    I think I'm stuck with enabling the 32mhz mode. PBPRO is aware but the pic is not running at 32mhz :?

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