View previous topic :: View next topic |
Author |
Message |
rovtech
Joined: 24 Sep 2006 Posts: 262
|
#use delay is twice what it should be |
Posted: Sat Dec 05, 2009 9:55 am |
|
|
The delay in this code should be 1/2 sec but is actually 1 sec
I have LEDs on B3, B2, B1, and B0 and simply count them up and down
Code: |
/* Pre-processor directives */
#include <16F722.H>
#fuses INTRC, NOWDT, PUT, NOPROTECT
#use delay (clock=16000000)
/* The main function */
void main(void)
{
// declare variables
int count = 0; // counter
// initialize port directions
set_tris_b(0b11100000); // set Port B7-B5 inputs, B4-B0 outputs
// main loop
while (1) // endless loop
{
while (count < 15)
{
output_b (count); // display count 0 to 14
delay_ms(500); // wait half a second
count++; // increment count to 15
}
while (count > 0)
{
output_b (count); // display count 15 to 1
delay_ms(500); // wait half a second
count--; // decrement count to 0
}
} // end of endless while loop
} // end of main function |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 05, 2009 9:59 am |
|
|
Doesn't PIC16F722 have a 8 MHz internal oscillator as all other PIC16?
What made you specify a clock frequency of 16 MHz? |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 10:02 am |
|
|
The spec sheet says 16MHz |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 10:07 am |
|
|
It works correctly if I use 8 MHz, but the spec sheet says the internal RC with PLL enabled is 16 MHz
OK, so I read the fine print. The default at reset is 8 MHz.
So I added SETUP_OSCILLATOR (OSC_16MHZ); ahead of the main loop but it still does 1 second delays
How do I make the oscillator go at 16 MHz and why the 8 MHz default? Is 16 MHz pushing things?
Last edited by rovtech on Sat Dec 05, 2009 10:28 am; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 05, 2009 10:27 am |
|
|
That's why I asked. I see, that the 16F722 has the capability of running at 16 MHz, but default OSCON is 8 MHz.
Apparently PCM doesn't understand the #use delay directive as a call to set it to 16 MHz... |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 10:31 am |
|
|
I should probably be replying instead of editing my post so I will copy here as a reply:
It works correctly if I use 8 MHz, but the spec sheet says the internal RC with PLL enabled is 16 MHz
OK, so I read the fine print. The default at reset is 8 MHz.
So I added SETUP_OSCILLATOR (OSC_16MHZ); ahead of the main loop but it still does 1 second delays
How do I make the oscillator go at 16 MHz and why the 8 MHz default? Is 16 MHz pushing things? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 05, 2009 10:56 am |
|
|
I checked the code and found, that oscillator frequency is already set from #use delay, also setup_oscillator is working. What's your compiler version? |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 12:10 pm |
|
|
A new challenge: How do I find my version?
The PCMUPD.exe file is 4.11.26.13 which should be what is installed.
MPLAB is 8.33
These were recently installed. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 05, 2009 12:23 pm |
|
|
Look at the top of your .LST file. _________________ Google and Forum Search are some of your best tools!!!!
Last edited by dyeatman on Sat Dec 05, 2009 12:23 pm; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 05, 2009 12:23 pm |
|
|
Your PCM version is 4.011. It doesn't handle PIC16F722 setup correctly. Even 4.084 doesn't. You have to set OSCON
manually. V4.011 most likely has other bugs, don't need to repeat what's been said in the forum all day.
Code: | #byte OSCCON = 0x90
//...
OSCCON = 0x30; |
|
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 12:37 pm |
|
|
I searched the site for information on finding my version, or my purchase history but cannot find anything except looking at the top of .lst.
How do I look at the .LST file? When I tried to open it outside of CCS the computer hung.
I opened CCS on its own (I usually use the IDE in MPLAB) and found version 4.089. I was not aware of problems but will search them. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 05, 2009 12:44 pm |
|
|
The .LST file is just a text file and can be opened with Notepad, Wordpad or similar. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 12:47 pm |
|
|
Thanks to everyone, setting OSCON manually works.
I assumed it was me not the compiler.
I would still like to know how to check my version within MPLAB. It is not obvious. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 05, 2009 12:57 pm |
|
|
V4.089 sounds much better, although the PIC16F772 support apparently isn't complete.
I wonder if you managed to disable *.lst file generation in your project somehow. |
|
|
rovtech
Joined: 24 Sep 2006 Posts: 262
|
|
Posted: Sat Dec 05, 2009 1:14 pm |
|
|
I never thought to open the .LST file in MPLAB. It is ver 4.089
The computer tried to open it in powerpoint and gave a freeze with black screen.
I would still like to know how to find my last purchase on the CCS site. The updates page says I can get it there but all I get is the billing page for another year of support. |
|
|
|