Osctune


Closed Thread
Results 1 to 36 of 36

Thread: Osctune

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    The sensor is capable of RS-485, both half and full-duplex, and I have used that before. The sensor board (0.25" wide X 1.9" long) has stuffing options that allow all sorts of protocols - I2C,RS232,RS-485.

    I have 8 or 10 different "Main" (or controller boards) already designed, any one of which that could control the sensor array. The particular feature set the customer wants, (SSH, SNMP, telnet, Real-Time Clock, Large event log) is on a board that doesn' t have an RS-485 chip. I don't want to design a new add on board at this time, so I'm going with the single-ended stuff. The customer will be using 30 sensors on 400' (total) of 4-wire cable. I think it will work!
    Charles Linquist

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    18F2620 hserout baud rates off consistently.

    I'm using hserout to send data to a PC running the old plx-daq excel data acquisition macro/control.
    It's worked in the past but i haven't used it for a long time.

    I have cranked up my pic speed to 32mhz using the PLL etc and that's confirmed by the simple flashing 1hz led trick.

    I set the ESUART with data from PicMulticalc using 32mhz as osc speed.

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 51 ' 38400 Baud @ 32MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

    The pic is transmitting data correctly but when checked with my logic probe I can see the baud rate is off.

    At 38400 it is actually 40000
    At 19200 it is 20000
    At 9600 it is 10000

    Seems very consistent and perhaps the windows serial port can't tolerate this error?

    Do you thing this is a ESUART register setting problem or a wayward oscillator that needs OSCTUNE tweaking?
    Last edited by retepsnikrep; - 15th February 2017 at 08:54.

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


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    I have a bunch of boards, all on a RS485 bus, all running the same code, and ONE board had to have its baudrate tweaked because it was off (I don't remember if I tweaked OSCTUNE or BAUDCON) so I'm leaning towards the oscillator not being quite where it should be.

    Do you have another PIC of the same type to try with?

    To verify if it's the oscillator, try generating a pulse with a known width and measure it.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    I tried another pic that produced exactly the same results

    The pic is transmitting data correctly but when checked with my logic probe I can see the baud rate is off.

    At 38400 it is actually 40000
    At 19200 it is 20000
    At 9600 it is 10000

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    you're sending a start bit, 8 bits of data and a stop bit all encoded as one symbol ie 10 bits .
    @say 9600 symbols per sec that yields a bit time of 10.4uS.
    how and what are you measuring ?
    logic probe ? do you mean logic analyser
    have you left off the start or stop bit in your calcs ?
    10 bits @ 10.4uS /bit = 9600 baud
    9 bits @ 10.4uS /bit = 10000 baud
    Warning I'm not a teacher

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    I'm measuring using Saleae Logic software.
    It reports the values I mentioned when using autobaud to detect the rate.

    https://www.saleae.com/downloads.

    I used to have this working but the problem is I don't know if it is the transmitter Hserout or receiver plx-daq is not working?

    The data looks correctly constructed with the logic analyser monitoring it.

    My config for reference is

    #CONFIG
    __CONFIG _CONFIG1H, _OSC_INTIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOREN_OFF_2L & _BORV_3_2L
    __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    __CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
    __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
    __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
    __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
    __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
    __CONFIG _CONFIG7H, _EBTRB_OFF_7H
    #ENDCONFIG

    DEFINE OSC 32 '32mhz Clock
    OSCCON = %01110000 'Internal 32 mhz Osc and stable
    OSCTUNE = %01000000 'Enable PLL 8mhz x 4
    WDTCON = %00010101 'Set watchdog Timer for 1 second
    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 = %10011000 'SET PORTC AS OUTPUTS EXCEPT PORT C3,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

    DEFINE LCD_DREG PORTB 'PORTB is LCD data port
    DEFINE LCD_DBIT 0 'PORTB.0 is the data LSB
    DEFINE LCD_RSREG PORTC 'RS is connected to PORTC.0
    DEFINE LCD_RSBIT 0
    DEFINE LCD_EREG PORTC 'EN is connected to PORTC.1
    DEFINE LCD_EBIT 1
    DEFINE LCD_BITS 8 '8 lines of data are used
    DEFINE LCD_LINES 4 'It is a 4-line display
    DEFINE LCD_COMMANDUS 1500 'Use 1500uS command delay
    DEFINE LCD_DATAUS 44 'Use 44uS data delay

    DEFINE ADC_BITS 8 'Set number of bits in result
    DEFINE ADC_CLOCK 3 'Set Clock source (3 = rc)
    DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS

    DEFINE CCP1_REG PORTC 'HPWM channel 1 pin Port C Backlight PWM Driver
    DEFINE CCP1_BIT 2 'HPWM channel 1 pin Bit 2

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 51 ' 38400 Baud @ 32MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Osctune

    Closure on my problem. I found the reciever i was using wanted idle low data not idle high... Arrrggggg.. I was sure it was high..

    Thanks for the advice. The transmitter was working correctly after all..

Members who have read this thread : 0

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