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

18F6722 Delay function work wrong ???

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



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

18F6722 Delay function work wrong ???
PostPosted: Tue Sep 27, 2011 9:02 am     Reply with quote

Embarassed
This is the first time I work with 18F6722!
I just program to export I/O normally and delay 1s but 18F6722 run close to 2s ???
Can somebody tell me the reason & how to solve this problem?
Here is my code :
Code:

#include <18F6722.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES TO                   
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES BBSIZ1K                  //1K words Boot Block size

#use delay(clock=40000000)

void main()
{
   while(true)
   {
      output_b(0xff);
      delay_ms(1000);
      output_b(0x00);
      delay_ms(1000);
   }
}
temtronic



Joined: 01 Jul 2010
Posts: 9216
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 9:20 am     Reply with quote

Are you really using a 40 MHz xtal ?
mrYalamen



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 10:42 am     Reply with quote

yes! I used 40Mhz in Proteus simulation and real hardware but the same result : near close to 2s !???
temtronic



Joined: 01 Jul 2010
Posts: 9216
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 10:50 am     Reply with quote

OK... you haven't selected a 'CPUdivider' fuse option so the default must be set.

If you show us the Fuses ( configuration words) that will show what's going on.
mrYalamen



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 11:36 am     Reply with quote

Thanks for your fast response !
here is all of fuses of 6722 .
you know i have used PLL funtion (H4 -> x4 external oscillator)that must use 10Mhz hardware so it work exactly 1s . But i still want to use (HS) -> high speed direct crystal 40Mhz ??? please !help me solve this prob ?
Code:

//////// Program memory: 65536x16  Data RAM: 3840  Stack: 31
//////// I/O: 54   Analog Pins: 12
//////// Data EEPROM: 1024
//////// C Scratch area: 00   ID Location: 200000
//////// Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,PROTECT,NOPROTECT,IESO,NOIESO
//////// Fuses: NOBROWNOUT,BROWNOUT,WDT1,WDT2,WDT4,WDT8,WDT16,WDT32,WDT64
//////// Fuses: WDT128,WDT,NOWDT,TO,BORV27,BORV42,BORV45,PUT,NOPUT,CPD,NOCPD
//////// Fuses: NOSTVREN,STVREN,NODEBUG,DEBUG,NOLVP,LVP,WRT,NOWRT,CPB,NOCPB
//////// Fuses: EBTRB,NOEBTRB,EBTR,NOEBTR,CCP2E7,CCP2C1,WRTD,NOWRTD,WRTC
//////// Fuses: NOWRTC,WRTB,NOWRTB,FCMEN,NOFCMEN,INTRC,INTRC_IO,BROWNOUT_SW
//////// Fuses: BROWNOUT_NOSL,WDT256,WDT512,WDT1024,WDT2048,WDT4096,WDT8192
//////// Fuses: WDT16384,WDT32768,LPT1OSC,NOLPT1OSC,MCLR,NOMCLR,XINST
//////// Fuses: NOXINST,BBSIZ1K,BBSIZ2K,BBSIZ4K,RC
////////
////////////////////////////////////////////////////////////////// I/O
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 12:52 pm     Reply with quote

Do you really have a 40 MHz crystal ? Or is it a 40 MHz oscillator ?

But anyway, the 18F6722 won't work with a 40 MHz crystal.
Download the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39646c.pdf
Look at this table
Quote:
TABLE 28-6: EXTERNAL CLOCK TIMING REQUIREMENTS

It says the highest frequency for HS mode is 25 MHz. HS mode is
used for a crystal.

The PIC can run at 40 MHz, but that's in EC mode with a external
oscillator chip, not a crystal.

Or you could use a 10 MHz crystal in HSPLL mode to get 40 MHz.
mrYalamen



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 6:38 pm     Reply with quote

Very Happy
Thank you very much about your answer!
I understood. It is difficult to read datasheet. But anyway, i will try to read again. And more questions ?
Can you give me the name of some oscillator chips in EC model ? thanks.

this is the way work well
Code:

#include <18F6722.h>
 
#device *=16
#device adc=10
#device HIGH_INTS=TRUE

#include <math.h>


#FUSES NOWDT                    //No Watch Dog Timer
                     
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or
#FUSES NOPUT
 #FUSES H4                        // use x4 external oscillator
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
 
#use delay(clock=40M )
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 27, 2011 7:17 pm     Reply with quote

Quote:
this is the way work well

#FUSES H4

#use delay(clock=40M )

That method is for 40 MHz with a 10 MHz crystal.

If that works well for you, then why do you want to use EC mode with
an external oscillator chip ? Why not use the 4x PLL mode with a 10 MHz
crystal ? It's much cheaper.

But if want to search for external oscillator chips, then go to
http://www.digikey.com

1. In search box, type in: oscillator and press the Go button.

2. Click on the link that says: Oscillators (6,285 items)

3. Then click on some parameters in these columns:

Type: XO (standard)
Frequency: 40MHz
Output: CMOS and also CMOS/TTL
Voltage Supply: 5v
Frequency Stability: 50ppm (or 100ppm or whatever you need)
Mounting Type: Choose either Surface Mount or Through Hole (or both)
Packaging: Choose both Bulk and Cut Tape

Then click the Apply Filters button and you will get some results.
They will probably all be SMD packages. Then click on the part number
of each part for more information such as prices and data sheets.
mrYalamen



Joined: 13 Aug 2011
Posts: 9
Location: Viet Nam

View user's profile Send private message

PostPosted: Wed Sep 28, 2011 9:56 am     Reply with quote

Thanks alot about your detailed instructions! you are a big man
I have found some oscillator ic.
You right, I would to use HSPLL osc because it's cheaper than other model but still fast. thank!
danyghi



Joined: 03 Aug 2008
Posts: 2

View user's profile Send private message

PostPosted: Sun Oct 02, 2011 9:25 am     Reply with quote

Quote:
Thanks alot about your detailed instructions! you are a big man
I have found some oscillator ic.
You right, I would to use HSPLL osc because it's cheaper than other model but still fast. thank!



HMMMM!!! what are you talking about ""still""??
10MHz with PLL x4 = 40MHz same freqvency
but dont forget to read the pdf in DC characteristics and to much the DC voltage with the maximum freqvence at the specific voltage from the graph.
In the hardware proj unlike simulation you need to select a crystal that it have the internal capacitor around 22pf (see pdf page 34) and for ext oscilators or extrasmall quartz with integrated capacitors and ground connection you can browse Farnell products oscillators crystals.

Last advice use a serial port for debug with serial always you can see if you set corect the fuse clock source etc...
danyghi



Joined: 03 Aug 2008
Posts: 2

View user's profile Send private message

PostPosted: Sun Oct 02, 2011 9:32 am     Reply with quote

If you don't need extra precision you can set the internal at 8mhz and PLLx4 which is 32MHz and you can tune osc a little bit higher with osctune.
Your micro controller it have a lot of options, use them.
If you want you can monitor with one of ad-s the source voltage and put an external thermometer from Dallas for example and increase stability by modifying osctune when you need it.
Finally use a capacitor with low ESR near vcc and Gnd of pic for a good decouplage.
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