View previous topic :: View next topic |
Author |
Message |
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
Load Frequency Oscillation from EEPROM? |
Posted: Tue Nov 20, 2007 8:42 am |
|
|
My goal it to set a switching frequency, save it to eeprom, and have it load the new saved frequency from eeprom upon startup.
I have tried:
SwitchingFrequency = read_SwitchingFrequency_from_eeprom(8);
#use delay(clock=SwitchingFrequency);
and it doesn't work. Is there a way to do it? thanks! I am brainstorming of ways to do it, but wouldn't mind some assistance. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Nov 20, 2007 9:31 am |
|
|
If you are using the internal clock then all you need to do is set the different bits, in the 16F688 they are contained in the register OSCCON, and you can change the speed on the fly. If you're running with an external crystal then, as far as I know, you are stuck with that speed. The #use delay() is a compile time command that tells the compiler what speed you are going to be running at. This allows the compiler to set the proper instructions to use with the delay_() command and also sets up the serial port timing. I haven't heard of being able to change the external speed, on the fly, but then I have been known to be wrong once.
Ronald |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Tue Nov 20, 2007 9:41 am |
|
|
i forgot to mention I'm using PCM and the PIC16F690. I am also using the internal oscillator. Thanks! |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Tue Nov 20, 2007 10:04 am |
|
|
What is the register OSCON? I understand that oscon stands for oscillator control, and I'm looking for it in the CCS manual. |
|
|
frequentguest Guest
|
|
Posted: Tue Nov 20, 2007 10:26 am |
|
|
What you're looking for is setup_oscillator(). |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Tue Nov 20, 2007 11:03 am |
|
|
I found the oscon in the special function registers menu under the view menu. What is the correct syntax to make changes to the OSCON register?
I tried OSCON = 60; but it doesn't work. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 20, 2007 12:19 pm |
|
|
Did you see the comment from FrequentGuest about the setup_oscillator()
function ?
When you switch oscillator frequencies, you'll also have to adjust any
delay statements that are in your program. Here is one possible way
to do it. (see the program below). Keep in mind that a #use delay()
statement affects all code that comes after it in the program. It's not
localized to one routine. It affects ALL lines of code that come after it in
the program. You'll note that I've placed the my_delay_ms() routine
down at the end of the program.
There might be other ways to do it. This it just one idea.
Code: |
#include <16F88.H>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2, ERRORS)
#define LOW 0
#define HIGH 1
int8 speed = LOW;
void my_delay_ms(int16 value);
//==================================
void main()
{
setup_oscillator(OSC_31KHZ);
speed = LOW;
my_delay_ms(1);
setup_oscillator(OSC_8MHZ);
speed = HIGH;
my_delay_ms(1);
while(1);
}
//================================
void my_delay_ms(int16 value)
{
if(speed == HIGH)
{
#use delay(clock=8000000)
delay_ms(value);
}
else
{
#use delay(clock=31000)
delay_ms(value);
}
} |
|
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Tue Nov 20, 2007 1:59 pm |
|
|
Perhaps if you could explain a bit more what you're trying to accomplish. It looks like you're trying to capture an event (calibration perhaps) and re-use the results from that event, the next time the PIC powers-up.
Like PCM Programmer mentioned, once you set a #use delay, it is set for everything that follows (unless you re-define the #use delay).
The following link shows a possible way to calibrate an internal oscillator over temperature, http://www.ccsinfo.com/forum/viewtopic.php?t=30426&highlight=, if it helps. |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Tue Nov 20, 2007 2:09 pm |
|
|
i'm programming a pic for a power supply and one of the requirements is a programmable switching frequency. The goal is to change the switching frequency (which I know how to do already), and save it so it becomes the new frequency that loads upon start up from then on until it is changed again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 20, 2007 2:15 pm |
|
|
OK, so the switching frequency has nothing to do with the speed of the
PIC. Our answers were based on your supposition that you need to
change the #use delay() statement to change the switching frequency.
In fact, you're likely using PWM (hardware or software) to run the
switching power supply, and all you want to do is find out how to save
the PWM frequency in eeprom.
It looks like I already answered this question for you a few days ago:
http://www.ccsinfo.com/forum/viewtopic.php?t=32722
The demo program in this post may also help you:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17 |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Tue Nov 20, 2007 3:44 pm |
|
|
languer, "Perhaps if you could explain a bit more what you're trying to accomplish. It looks like you're trying to capture an event (calibration perhaps) and re-use the results from that event, the next time the PIC powers-up."
That is correct. The only part I need help with is "the re-use results the next time the PIC powers-up."
PCM programmer wrote: | OK, so the switching frequency has nothing to do with the speed of the
PIC. Our answers were based on your supposition that you need to
change the #use delay() statement to change the switching frequency.
In fact, you're likely using PWM (hardware or software) to run the
switching power supply, and all you want to do is find out how to save
the PWM frequency in eeprom.
It looks like I already answered this question for you a few days ago:
http://www.ccsinfo.com/forum/viewtopic.php?t=32722
The demo program in this post may also help you:
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17 |
PCM - Sorry, I just re-read my last statement saw how it was confusing. I now know how to change the frequency and save it to EEPROM (thanks to your help), and I just want to load the saved frequency from eeprom so it becomes the new speed of the pic upon startup.
I am a big fat noob, but I'm making a lot of progress on this project thanks to forum. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 20, 2007 3:47 pm |
|
|
See my 2nd link. Look at the line that reads eeprom at address 0,
just after the call to lcd_init(). |
|
|
|