CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Load Frequency Oscillation from EEPROM?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ThomasC



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

Load Frequency Oscillation from EEPROM?
PostPosted: Tue Nov 20, 2007 8:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 9:31 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 9:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 10:04 am     Reply with quote

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







PostPosted: Tue Nov 20, 2007 10:26 am     Reply with quote

What you're looking for is setup_oscillator().
ThomasC



Joined: 09 Oct 2007
Posts: 62

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 11:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 12:19 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 1:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 2:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 2:15 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 3:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 3:47 pm     Reply with quote

See my 2nd link. Look at the line that reads eeprom at address 0,
just after the call to lcd_init().
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group