Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 7th November 2008, 09:28 AM   #1
Default MikroC Delay_ms() problem!!!

Hi,
i am using mikroC as compiler and i want to program pic18f4550 .whenever i try to use delay functions of mikroC it produces wrong delays.For example i wrote
Delay_ms(10);
it produces 1 seconed delay
can anyone help me?


my whole program is:


void main()
{
TRISB=0;
for(;; ){
PORTB=0x4F;
Delay_us(10000);
PORTB=0x00;
Delay_us(10000);
}
}
cGr is offline  
Old 7th November 2008, 09:38 AM   #2
Default

I would assume that you need to tell the compiler the speed of your oscillator. Normally you would have something like, clock=20000000 or OSC=32768.

Mike.
Pommie is online now  
Old 7th November 2008, 12:49 PM   #3
Default

Quote:
Originally Posted by cGr View Post
Hi,
i am using mikroC as compiler and i want to program pic18f4550 .whenever i try to use delay functions of mikroC it produces wrong delays.For example i wrote
Delay_ms(10);
it produces 1 seconed delay
can anyone help me?
When you open your project, on the left hand side you have "clock" field where you need to put the speed your uC is running on. You can also go to project properties and set it there. Note that this is not always equal to the crystal speed.

For example, if you use PLL and your crystal is 10MHz the uC will run on 40MHz and not on 10MHz hence you have to enter 40000000 in that field and not 10000000.

The delay_*() functions generate delay loop relating to this field so if you enter wrong value there, all delay* functions will create "wrong" delay.

attached example pic
Attached Thumbnails
MikroC Delay_ms() problem!!!-untitled-1.jpg  

Last edited by arhi; 7th November 2008 at 12:58 PM.
arhi is offline  
Reply

Tags
delayms, mikroc, problem

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
mikroC problem colin mac Micro Controllers 12 22nd July 2008 01:02 PM
mikroC lib troubble Kryten Micro Controllers 17 28th May 2008 09:56 AM
mikroC demo version limits ssylee Micro Controllers 8 19th October 2007 09:21 PM
Servo motor~~~~ problem~.....shaking problem!!!!! Gundam82 Robotics Chat 10 4th October 2004 08:12 PM



All times are GMT. The time now is 01:44 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker