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

PCWH 3.221 and delay problem

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



Joined: 18 Mar 2005
Posts: 5

View user's profile Send private message

PCWH 3.221 and delay problem
PostPosted: Fri Mar 18, 2005 11:38 am     Reply with quote

I'm having some issues with delay_us function. I have this simple code:

Code:
#include <16F819.h>
#device adc=8
#use delay(clock=8000000)
#fuses NOWDT,INTRC_IO, PUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT

void main()
{
     while(TRUE)
     {
          output_b(0xff);
          delay_us(2000);
          output_b(0x00);
          delay_us(18000);
     }
}


The output is a led being lighted one time each 2-3 seconds, that it's not the desired output.
Guest








PostPosted: Fri Mar 18, 2005 12:09 pm     Reply with quote

I've verified that it's not the delay function, as i created the "mydelay" function and get the same fault output.

I don't know what's happening.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 12:16 pm     Reply with quote

If you look in the 16F819 data sheet, you'll see that this chip has got
multiple frequencies for the internal oscillator. So that should be a
clue right away, that maybe one of the lower frequencies is selected.

The data sheet shows that the frequency is selected by the OSCCON
register. It also shows that the power-reset state of that register is all
0's, which selects 31.25 KHz.

There are a few ways to set OSCCON for 8 MHz operation.

If you put the #use delay() statement below the #fuses INTRC_IO
statement, then the compiler will insert code to configure OSCCON
for 8 MHz operation into the start-up code.
Code:

#include <16F819.h>
#device adc=8
#fuses NOWDT,INTRC_IO, PUT, NOMCLR     // (etc.)
#use delay(clock=8000000)    // Put this line below the #fuses statement


But that's probably a little hard to remember, so a better way would
be to use the setup_oscillator() function right at the start of main().

Code:
#include <16F819.h>
#device adc=8
#use delay(clock=8000000)
#fuses NOWDT,INTRC_IO, PUT, NOMCLR       //  (etc.)

void main()
{
setup_oscillator(OSC_8MHZ);    // Add this line.

     while(TRUE)
     {
          output_b(0xff);
          delay_us(2000);
          output_b(0x00);
          delay_us(18000);
     }
}



setup_oscillator() works OK in your version. In some earlier versions
it may not work correctly, so then you would set OSCCON manually,
after defining the register address with a #byte statement. Example:

#include <16F819.h>
#device adc=8
#use delay(clock=8000000)
#fuses NOWDT,INTRC_IO, PUT, NOMCLR // (etc.)

#byte OSCCON = 0x8F

void main()
{
OSCCON = 0x70; // Select 8 MHz internal oscillator

while(TRUE)
{
output_b(0xff);
delay_us(2000);
output_b(0x00);
delay_us(18000);
}
}
jvalencia



Joined: 18 Mar 2005
Posts: 5

View user's profile Send private message

PostPosted: Fri Mar 18, 2005 12:39 pm     Reply with quote

Yeah it worked!

Thanks a lot.
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