View previous topic :: View next topic |
Author |
Message |
Askjerry
Joined: 06 May 2004 Posts: 20 Location: Austin, Texas
|
Posted: Thu May 06, 2004 5:07 am Post subject: Selecting between intrnal and external clock source |
|
|
I just picked up some MEGA-8 chips and they have an internal 1MHZ OSC. I want to run them with an external 10MHZ crystal and/or ceramic resonator.
Reading through the PDF file for the chip, I see that there is a register/fuse CKSEL and SUP that get a number programmed into them to select the timing options.
What I cannot figure out is how to set BASCOM to select these. If I use the $CRYSTAL = 10000000 command... that will tell the compiler to assume 10 MHz... but I do not think it actually sets the chip to change from the default 1MHz INTERNAL OCS does it?
If not... how do I change it?
Jerry |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu May 06, 2004 10:52 pm Post subject: |
|
|
The $CRYSTAL directive only task is to inform the compiler about the speed of the oscillator. With this info, the baudrate can be calculated and the waitms, wait , etc. delayloops can be calculated.
But while it is important to specify the correct $crystal value, it does not set the value of the crystal oscillator self.
You need to change some fusebits to select a different oscillator frequency, or to select an external oscillator or crystal.
The Sample Electronics, STK200 , STK300 and all parallel port based programmers support changing the fusebits. Select Program, Manual (1.11.7.4 version and up) and at the programming window, select the Lock & Fusebits TAB.
The settings will be read and shown in a list.
You can now change settings and press Write Fusebits button.
It is VERY IMPORTANT that you choose the right value. When you choose an external oscillator, and you provide no external clock signal, the micro will appear dead.
To overcome this is simple ; connect a clock signal to the X1 input and change the fuse bits again. You can use a running micro and connect X2 output to X1 input.
I advise to read the datasheet that will explain various fuse and lock bit settings. Each chip has different options. _________________ Mark |
|
Back to top |
|
|
Askjerry
Joined: 06 May 2004 Posts: 20 Location: Austin, Texas
|
Posted: Fri May 07, 2004 12:07 pm Post subject: |
|
|
Okay... I guess I need to upgrade... I was using 1.11.7.3 when I posted. I'll download the latest and see if I can find that.
Thanks for the assistance.
Jerry |
|
Back to top |
|
|
Fanie
Joined: 19 Jun 2004 Posts: 1
|
Posted: Sat Jun 19, 2004 7:28 am Post subject: Selecting between internal and external clock source |
|
|
Hi there
I am using a MEGA-8 and would like to know if it is at all possible to switch between Internal 8Mhz oscilator and an external 32Khz osc programaticaly? To save power in powerdown mode. From the datasheet i cannot figure out if there will be any less power consumption between 8Mhz and 32Khz in power down mode. |
|
Back to top |
|
|
Jeremy Wempren
Joined: 18 Jun 2004 Posts: 8
|
Posted: Sat Jun 19, 2004 6:14 pm Post subject: |
|
|
RE:
I just picked up some MEGA-8 chips and they have an internal 1MHZ OSC. I want to run them with an external 10MHZ crystal and/or ceramic resonator.
I don't think it's possible at runtime to change this fuse setting. i have used an ECS-3006 selectable clock gen (20Mhz 15Mhz 10Mhz ect ect) and used a few pins on the atmen to switch between 20Mhz and a few other freqs, but this is the only way i know how to do it. if you do though be sure to give the system time to adjust to the new freq before you do anything. after that i have found that it works fine. (and this was on a 2313 hehe double overclocked that baby, as there only rated at 10Mhz LOL) i used it as a kind of TURBO for when i needed the micro for short time periods to perform some actions in high order.)
you just have to make sure and do all the calculations (UBBR wait states timers and what not) yourself as bascom is not very good at compiling code for mixed freq applications. make sure you have a reg location that you set asside as a flag for your diffrent freqs and before any aperation that uses timers or wait or anything thats time critical you check the flag and adjust your settings accordingly.
i found that the atmels are damned mean chips that don't die easily. it was great fun to see if i could get it to miss a step or glitch.
have fun
JW |
|
Back to top |
|
|
Askjerry
Joined: 06 May 2004 Posts: 20 Location: Austin, Texas
|
Posted: Sun Jul 11, 2004 5:42 am Post subject: |
|
|
I contacted Mark and got an upgrade. This solved the problem. He then sent me yet another upgrade where it can send the command to the BASIC file which will tell the programmer to se the fusebits when programmed.
There is also another trick I picked up to allow me to set the chip type in the code as well.
SAMPLE:
'------------------------------------------------------------------------
' Set Programmer Options
$prog &HFF , &HE1 , &HD9 , &H00
' Set the programmer for a Mega-8 chip
$regfile = "m8def.dat"
' Set the frequency
$crystal = 1000000
'------------------------------------------------------------------------
Pretty neat stuff huh?!?
Jerry |
|
Back to top |
|
|
|