External osc defines


Closed Thread
Results 1 to 21 of 21
  1. #1
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116

    Default External osc defines

    Hi Insiders,

    Iīm trying to convince a Pic16F628A to work at 20MHz (yes it is a 20Mhz device) with an external canned oscillator

    but i donīt get the right configs:

    @config_EXTCLK_OSC

    this shows no error when compiled but the setup doesnīt work

    this is my simple testcode.

    NEVER GOT ANY 20MHZ DEVICE WORKING!!!! only 10MHz or below.

    '************************************************* *******************************************
    ' 16F628A 4 Mhz crystal
    ' damn program should blink an LED every time a pulse goes into RB.0
    ' later a value should be serial loaded and set a delay before the blink pulse
    '************************************************* *******************************************

    '
    ' DEFINITIONS


    @config_EXTCLK_OSC


    CMCON=%00000111
    led var portb.7



    ' START OF MAIN PROGRAM
    '
    CMCON = 7 ' RA0-RA3 are digital I/O
    TRISA = 0 ' PORT A is output
    TRISB = 1 ' RB0 is Input others output



    main:
    led = 1
    pause 500
    led = 0
    pause 500
    goto main


    END ' End of program

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Try this:

    @ __CONFIG_EXTCLK_OSC
    DEFINE OSC 20
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Make sure you call-out all config options you need in the config directive line. Otherwise
    they default to options you may not be aware of that can stop you dead in your tracks.

    /MCLR is by default reset, and LVP is by default on. If you only indclude _EXTCLK_OSC, then
    LVP is enabled, and can really screw things up.

    Give this a shot.

    Code:
      @ __config _EXTCLK_OSC & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF
      
      DEFINE OSC 20 
      LED VAR PORTB.7
      CMCON = 7 ' RA0-RA3 are digital I/O
      PORTB = %01111111 ' set port latches
      TRISB = %01111111 ' RB7 is output, rest are inputs.
    
    main:
      led = 1
      pause 500
      led = 0
      pause 500
      goto main
    
      END ' End of program
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default 20MHz no go

    Hi Bruce,

    I tried your Program but it gave me a compilation error I didnīt understand something like out of memory.

    I tried Joes Define instead which at least showed no compilation error.

    My small setup sits on a veroboard and I tried to hold all Cu-lines as short as possible and used the some capacitors etc.

    99% of the time it didnīt work but some seconds the Led blinked as expected.

    Tried some other 20Mhz 16F628A but they showed all the same behavior. Scope said the canned Oscillator is ok,. tried to use different resistors in line, parallel , from +5V to signal because it could have an open collector output......

    In the evening I try again with a crystal. Damned!

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    To use this config directive you need to use the MPASM assembler, and comment out any
    MPASM config statments in the default PBP device header file.

    If you're using the PM assembler, then change it to;

    @ DEVICE EXTCLK_OSC, WDT_OFF, MCLR_OFF, LVP_OFF, PROTECT_OFF

    If you're still having trouble see this thread http://www.picbasic.co.uk/forum/showthread.php?t=543
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Mpasm

    Hi Bruce,

    Iīm using Micrchips MPASM and PBP 2.50

    Did you use 20 MHz on a veroboard?

  7. #7
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I have never used vero board or a 20MHz canned type TTL clock oscillator, but I do use
    20MHz crystals & resonators on breadboards pretty often.

    What is the error you're seeing when you compile? The example I posted compiles fine here!

    Edit: Which PIC are you compiling for? There are differences in config options between some
    device types.
    Last edited by Bruce; - 12th February 2008 at 12:47. Reason: PIC type
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  8. #8
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Talking Found mistake on design homepage

    Hi Guys!

    This works:

    '************************************************* *******************************************
    ' 16F628A 20Mhz extern canned Oscillator
    ' damn program should blink an LED
    ' Yeah Works!
    '************************************************* *******************************************

    @config_EXTCLK_OSC


    DEFINE OSC 20
    LED VAR PORTB.7
    CMCON = 7 ' RA0-RA3 are digital I/O

    TRISB = %01111111 ' RB7 is output, rest are inputs.

    main:
    led = 1
    pause 500
    led = 0
    pause 500
    goto main

    END ' End of program

    And heres the mistake:
    http://hobby_elec.piclist.com/e_pic8_8.htm

    Look at the osc wiring diagram: ext osc MUST be connected to RA6! hahahaha!

  9. #9
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I'm glad you got that working, however, this @config_EXTCLK_OSC is totally not a good or valid config directive.

    It doesn't throw an error, but it also doesn't do anything. I suspect you have whatever default config settings in the device .INC file that are actually being used.

    It may work, but you will have issues down the road with your canned oscillator, PIC, or both shortly. RA6 on this device is NOT the external clock input. RA7 is.

    If you have a canned oscillator, like the 2nd picture in this link http://hobby_elec.piclist.com/e_pic8_8.htm then you do not want to connect the output of this oscillator to RA6.

    If you have XT, HS or any other config setting to enable the OSC2 output, then you have two outputs connected together, and you'll want a lot of spare parts.

    If you're using the default PM assembler;

    @ DEVICE EXTCLK_OSC, WDT_OFF, MCLR_OFF, LVP_OFF, PROTECT_OFF

    If you have MPASM selected as the assembler;

    @ __config _EXTCLK_OSC & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF

    Note: Option #2 will indeed return an error unless you have the MPASM config line in the default 16F628A.INC file commented out.

    If your device programmer supports it, simply compile, open the .hex file, and verify your config settings. If it is NOT set to EC oscillator, then you will for sure have major problems down the road. Just FYI.

    It may work with XT or HS since you have a canned oscillator output connected, but I wouldn't expect something like this to last since OSC2 would also be trying to drive the external crystal.

    If you have a 20MHz crystal, then the circuit shown in the 1st graphic is the way to go.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  10. #10
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Mugelpower View Post
    Hi Guys!

    This works:

    '************************************************* *******************************************
    ' 16F628A 20Mhz extern canned Oscillator
    ' damn program should blink an LED
    ' Yeah Works!
    '************************************************* *******************************************

    <font color=red> @config_EXTCLK_OSC</font color> ' Incorrect way<br>
    <font color = blue>@ __config _EXTCLK_OSC & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF</font color> ; MPASM Assembler<br>
    <font color=green>@ DEVICE EXTCLK_OSC, WDT_OFF, MCLR_OFF, LVP_OFF, PROTECT_OFF</font color> ; PM ASSEMBLER


    DEFINE OSC 20
    LED VAR PORTB.7
    CMCON = 7 ' RA0-RA3 are digital I/O

    TRISB = %01111111 ' RB7 is output, rest are inputs.

    main:
    led = 1
    pause 500
    led = 0
    pause 500
    goto main

    END ' End of program

    And heres the mistake:
    http://hobby_elec.piclist.com/e_pic8_8.htm

    Look at the osc wiring diagram: ext osc MUST be connected to RA6! hahahaha!
    I'll bet you had to set the OSC fuse manually on the programmer ! Do it the way Bruce showed you and it will set automaticly when you load the hex file.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  11. #11
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Default osc setting manually no go

    Hi Joe,

    iīm using the PicKit2 and i didnīt find any osc settings in the programmer window. That was what I tried at first.

    had the Velleman programmer before and this had the possibility to set osc configs. But that one died long ago.....simply didnt work anymore.

    on the other hand: PicKit2 is fast an easy to use and supports everything, even the 16F628A...hahaha

  12. #12
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Question RA6 works.....RA7 not!

    Hi Bruce,

    I know the datasheet shows RA7 is external clock in..but I dont get it working. When connecting to RA6 it works. should I try a long-time test if the pic gets to hot? maybe a resistor between canned oscillator and PIC?

  13. #13
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Mugelpower,
    Here is what I think, <b>I say think because I do not definately know.</b> Being that your config fuse setting is WRONG, I think your PIC is not properly set up for EXT OSC and that is why it will not accept input on RA7, I THINK it it using the oscillator as a crystal, somehow getting enough signal to work, elsewise it may be defaulting to int osc, who can say? Try sending out some serial data to a serial lcd and see if it scrambles the data, better yet correct your config statement and then try the OSC on it's proper pin. I compiled your code both ways and the hex files have some distinct differences. One more thought, the PIC is probably using the default config statement in the 16F628A.inc file, unless you have commented it out.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try the attached .hex file with your oscillator connected to RA7. This is your code compiled
    with EC oscillator settings I posted previously.

    If it doesn't work I would guess you have a bad PIC, oscillator, or both. Or your programmer
    is not using the config options embedded in the .HEX file.

    This @config_EXTCLK_OSC is not valid, so it does nothing to set EC mode. Whatever config
    options you're getting programmed into the PIC are the defaults in 16F628a.inc. Normally osc
    is set to XT in the defaults. In this mode, OSC2 provides the drive for an external crystal circuit
    like the one shown in first diagram on the link you posted.
    Attached Files Attached Files
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Cool Hex file

    Thanks Bruce,

    will test that in the evening. Its now 3 pm. will take another 4 hrs til Iīm home.

    Does That mean MPASM doesnīt handle extern osc settings ?

    Or does it mean the PicKit2 sets its own default osc settings?


    very strange.

  16. #16
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    MPASM works just fine with any config directives the PIC has, but they are different than config directives the PM assembler expects. See the thread I linked to above for the details on config use. Melanie does a nice job explaining this.

    I don't have a PicKit2, so I can't really say how it works, but I would assume it can read & use config options embedded in the .HEX file, or give you an over-ride option.

    Maybe someone else here familiar with the PicKit2 can comment on this one?

    Look in the 16F628a.inc file in your PBP directory. If you use PM, it uses the top config defaults. If you use MPASM, then the 2nd default config options are used.

    When you insert a bogus config directive in your code, it isn't used, and of course it has no bearing on what config options will be embedded in the .HEX file.

    Read the thread by Melanie I linked to earlier. It is well worth the time.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  17. #17
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Wink The hex file works

    Thanks Bruce,

    your file is ok and now 20Mhz could find their way via RA7!

    I will try to grasp the "Define-thingy" by reading and trying.

    Ha!

  18. #18
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Question Impossible to compile

    Hi Bruce,

    as I told you your hex code of my small program really works.
    But if I take your previously shown config fuses I get only a compilation error

    '************************************************* *******************************************
    ' 16F628A 20Mhz extern canned Oscillator
    ' damn program should blink an LED
    ' Igot that compilation error
    '************************************************* *****************************************


    @ __config _EXTCLK_OSC & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF



    LED VAR PORTB.7
    CMCON = 7 ' RA0-RA3 are digital I/O

    TRISB = %01111111 ' RB7 is output, rest are inputs.

    main:
    led = 1
    pause 500
    led = 0
    pause 500
    goto main

    END ' End of program

    Error[118] c:\pic\16f628a\blinkb~2.asm : Overwriting previous address contents (2007)

    when I use only this config:
    @ __config _EXTCLK_OSC

    I get no comp. error but the thing dosnīt work either.

    is an external Osc. with 20 Mhz a no go for PBP ?

  19. #19
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you would just please take the time to read this thread http://www.picbasic.co.uk/forum/showthread.php?t=543 you should get what's happening. If not then let me know.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  20. #20
    Join Date
    Jan 2008
    Location
    Selm, Germany
    Posts
    116


    Did you find this post helpful? Yes | No

    Talking Took time to read

    Hi Bruce,

    yeeeees I understood and read the whole thread and you were right: there it all stood.

    The most "difficult" part of it was to find out in WHICH of those .INC files the config fuses had to be changed.
    there were at least three of them and 2 were in the PBPDEMO folder and those were the ones but I dunno which of those two. commented the configs in both.

    After that my BLINKBILLIG20MHz blinked way too fast and the "DEFINE osc 20" programming and compiling worked not for the first 4 times although I erased the PIC complete before programming.

    Now it does. And reacts on changing the osc frequency.

    thanks a bundle.

    I guess your nerves get friggled up with guys like me asking the "obvious" for the 20th time, huh?

    next try will be 3 pics with one canned 20Mhz oscillator.....

  21. #21
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I guess your nerves get friggled up with guys like me asking the "obvious" for the 20th time, huh?
    Not at all. I enjoy answering questions here because I will almost always learn something in the process, and I enjoy learning. A nice by-product of this is that I get to help someone else in the process of learning new things myself.

    I just see no point in re-typing an answer to a question that has already been thoroughly covered in another thread.

    If someone has taken the time to read information in a thread I linked to, the data sheet, manual, etc, and they still have a question about some part of it they aren't 100% clear on, then I'm more than happy to attempt to elaborate.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Internal vs. external osc for comms
    By mtripoli in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th January 2010, 14:58
  2. Replies: 1
    Last Post: - 28th January 2010, 22:15
  3. 18F1320 with external osc
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th February 2008, 22:32
  4. How to use an external oscillator
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th February 2008, 14:19
  5. External clock
    By Firegod in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2007, 00:53

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