PDA

View Full Version : External osc defines



Mugelpower
- 10th February 2008, 19:13
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

Archangel
- 10th February 2008, 21:35
Try this:

@ __CONFIG_EXTCLK_OSC
DEFINE OSC 20

Bruce
- 10th February 2008, 22:14
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.



@ __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

Mugelpower
- 12th February 2008, 07:37
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!

Bruce
- 12th February 2008, 11:10
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

Mugelpower
- 12th February 2008, 12:30
Hi Bruce,

Iīm using Micrchips MPASM and PBP 2.50

Did you use 20 MHz on a veroboard?

Bruce
- 12th February 2008, 12:45
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.

Mugelpower
- 12th February 2008, 20:21
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!

Bruce
- 13th February 2008, 00:48
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.

Archangel
- 13th February 2008, 01:07
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.

Mugelpower
- 13th February 2008, 08:38
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

Mugelpower
- 13th February 2008, 08:45
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?

Archangel
- 13th February 2008, 09:56
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.

Bruce
- 13th February 2008, 12:20
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.

Mugelpower
- 13th February 2008, 13:55
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.

Bruce
- 13th February 2008, 14:27
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.

Mugelpower
- 13th February 2008, 19:25
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!

Mugelpower
- 13th February 2008, 20:35
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 ?

Bruce
- 13th February 2008, 20:48
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.

Mugelpower
- 17th February 2008, 10:13
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.....

Bruce
- 17th February 2008, 14:56
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.