Oscillator/Hserout woes


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Oscillator/Hserout woes

    Need a sanity check here!

    I've been runing on an external 20Mhz resonator ....HSEROUT worked fine.

    now want to go with the PIC's 4Mhz internal oscillator (to free up a couple of pins)...but no matter what I do, HSEROUT is garbage.

    I'm using MPASM... the16F690inc file has a couple of options that I'm not clear about...

    _INTRC_OSC_NOCLKOUT
    _INTOSC

    ...could someone tell me why two options that look similar? (I've tried both....but sticking with _INTRC_OSC_NOCLKOUT )

    Anyway, back to my problem....

    Code:
    @ __CONFIG _FCMEN_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _IESO_OFF & _BOR_OFF & _PWRTE_OFF
    
    DEFINE  OSC 4          ' set Oscillator at 4Mhz.
    
    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 25  ' 9600 Baud @ 4MHz, 0.16%
    SPBRGH = 0
    BAUDCTL.3 = 1         ' Enable 16 bit baudrate generator
    
    
    
    Include "modedefs.bas"
    
    ANSELH=0
    ANSEL=0
    CM1CON0 =0
    CM2CON0 =0
    CM2CON1 =0
    adcon1=0
    TRISB.6 = 1
    TRISB.7 = 0
    TRISC=%00000000 ; set all Port C pins as outputs
    rcsta.7=1 'SPEN serial port enable bi
    
    
    loop1: 
    hserout ["hello", 13, 10]
    pause 250
    goto loop1
    end
    Grateful for any input here....I'm going crazy looking at this problem for hours!

    Edit: Just rolled back to the external 20Mhz resonator oscillator - Hserout works just fine - could it be the internal oscillator is out of spec & therefore wrong after being divided down?
    Last edited by HankMcSpank; - 10th October 2010 at 13:13.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    Hi Hank,
    Have you verified that the PIC is running at 4Mhz? Toggle a LED at 1Hz or something will show you that if it's 4Mhz (which if I'm not mistaken is the default for the internal oscialltor) or if it's something else.

    Have you tried to simply DEFINE HSER_BAUD 9600 ?

    Next, have you tried another baudrate, say 2400baud? The specs says that internal oscilaltor is off by no more than +/-1%. I'm not sure what's tolarable when it comes to RS232 but lowering the generated baudrate will lower any fault introduced by the oscillator - worth a try.

    Finally, the internal oscillator can be setup to either output the clocksignal on the OSC/CLKOUT pin on a pin or not - that's the two options.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default

    You should set the OSCCON register in your code. There are a lot of speed options for your chip, from 8mhz to 32khz. Looks like it defaults to 8mhz if left untouched.
    http://www.scalerobotics.com

  4. #4
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by scalerobotics View Post
    You should set the OSCCON register in your code. There are a lot of speed options for your chip, from 8mhz to 32khz. Looks like it defaults to 8mhz if left untouched.
    Thanks for the input guys

    As it goes (out of desperation), I tried a few permutations of OSCCON prior to posting (but wasn't too sure whether the OSCCON setting overode the define command or not)

    I have to say all the config setting surrounding something as elementary as setting an oscillator up is very confusing!

    So having got the fuse correct ( _INTRC_OSC_NOCLKOUT ...at least that's what's in the 16f690.inc MPSAM file)

    Having got the define correct. (define osc 4 ....4Mhz)

    The OSCCON still needs setting? (bear with me here - I seldom change this stuff.....if OSCCON still needs setting what's the purpose of the DEFINE command?)

    I tried getting the interal oscillator presented on the associated IO pins (to see if I could scope them - failed! IS there something unique about the clock that makes it invisible? lol)

    I tried a whole heap of permutations - the Hserout settings I posted were derived from Mr E's calculator.

    The weird things is ...when on internal oscialltor, most of the 'format' of the text onscreen was almost there (eg tabs were in the right places, therefore forming columns as the lines wrapped ...just gobbledegook when on the internal oscillator). I'll come back to this later, but for the time being I'll stick with 20Mhz!

    Incidentally, when I scope the PICs OSC pins when using an external resonator - I can't scope the signal either ....I'm starting to think this is personal & that the clock oscillator from just me!!!!! (not saying I'm paranoid - I used to play rugby but gave up becuase everytime there was a scrum, I thought they were talking about me)
    Last edited by HankMcSpank; - 10th October 2010 at 15:49.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HankMcSpank View Post
    Having got the define correct. (define osc 4 ....4Mhz)

    The OSCCON still needs setting? (bear with me here - I seldom change this stuff.....if OSCCON still needs setting what's the purpose of the DEFINE command?)

    I tried getting the interal oscillator presented on the associated IO pins (to see if I could scop them - failed! IS there something unique about the clock that makes it invisible? lol)

    I tried a whole heap of permutations - the Hserout settings I posted were derived from Mr E's calculator.
    No, you were correct, it defaults to 4 mhz, and should not need to be set, unless you want to try 8 mhz. Which, maybe you should, just for fun. But try what Henrik suggested with verifying your osc speed by toggling an led, and see what you get, just to be sure.
    Last edited by ScaleRobotics; - 10th October 2010 at 16:43.
    http://www.scalerobotics.com

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default

    Hi,
    DEFINE OSC 4 doesn't do anything with the PICs registers or config "fuses". It simply tells the compiler that you are intending to run the chip at 4Mhz so it knows how to calculate the correct amount of cycles for your PAUSE 250 etc.

    The internal oscillator on the '690 is fixed* at 8Mhz but the postscaler (controlled by bits 4, 5 and 6 in the OSCCON register) defaults to a divide by 2 ratio so you end up with 4Mhz as the default. So really, it should be running at 4Mhz.

    * The "fixed" 8Mhz oscillator can be tuned by changing the OSCTUNE register.

    When you tried to get the CLKOUT to work, did you set the pin to output? (TRISA.4 = 0)

    /Henrik.

    EDIT: Running at 4Mhz you should see a 1Mhz signal on the CLKOUT pin.

  7. #7
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    DEFINE OSC 4 doesn't do anything with the PICs registers or config "fuses". It simply tells the compiler that you are intending to run the chip at 4Mhz so it knows how to calculate the correct amount of cycles for your PAUSE 250 etc.

    The internal oscillator on the '690 is fixed* at 8Mhz but the postscaler (controlled by bits 4, 5 and 6 in the OSCCON register) defaults to a divide by 2 ratio so you end up with 4Mhz as the default. So really, it should be running at 4Mhz.

    * The "fixed" 8Mhz oscillator can be tuned by changing the OSCTUNE register.

    When you tried to get the CLKOUT to work, did you set the pin to output? (TRISA.4 = 0)

    /Henrik.

    EDIT: Running at 4Mhz you should see a 1Mhz signal on the CLKOUT pin.
    Great stuff Henrik - like I say, in the end I went back to 20Mhz (& all the associated pin rejigging that entails from having to put back in the an external resonator!)...I don't have the heart or inner strength to now 'rejg' my 'rejig' so to speak ......but I *will* revisit this with the advice/knowledge gained here (I'd dearly love to see some form of clock coming out of the pesky pins - if for no other reason to establish that the PIC isn't holding a grudge against me!)

    A hearty thanks!

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


    Did you find this post helpful? Yes | No

    Default

    Sorry, it does default to 4mhz, I can't read binary until I have my coffee ... sorry.
    http://www.scalerobotics.com

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