Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

MikroC Delay_ms() problem!!!

Status
Not open for further replies.

cGr

New Member
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);
}
}
 
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.
 
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
 

Attachments

  • Untitled-1.jpg
    Untitled-1.jpg
    135.3 KB · Views: 1,307
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top