Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

1 microsecond delay using c programming

Status
Not open for further replies.

sme7000

Newbie level 6
Joined
Dec 16, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
malaysia
Activity points
1,387
do anyone have a code in c programming for 1 microseconds delay? i'm using PIC16F877A with 20MHz OSC(oscillator). :?:
 

asm("nop") is equivalent to delay of 200 ns @ 20MHZ CLK
--
Amr Ali
 

Remember that 1 instruction cycle equals 4 clock impulses ( clock cycles ). So if you got 20 MHz it makes 5000000 instructions per second. And NOP takes 1 instruction cycle and very low power.

Try to make a progress by dividing numbers and then go for loops.
 

If your delay is 1 microsecond, use 5 nop instructions.
--
Amr Ali
 

i can be don by C built in function "delay()" with "dos.h" header file:D
 

Is it working on the PIC specified?
--
Amr Ali
 

i want to generate '1' and '0' with the intervals between 10 microseconds..can anyone give me a instruction how to do this..i'm using c programming to build this operation.
 

between 10 microseconds and what?
--
Amr Ali
 

The time intervals and the MCU you are using might be a mismatch if you want to program in "C". The 20 MHz PIC is simply a bit slow to execute enough instructions for a "C" delay function within 1 us.

Either you go to ASM or to a much faster processor.

Just my2cents, Bob
 

hi,

i'm looking for a solution for ATMega128 microcontroller and i want to control the I/O pins with microsecond precision i.e. each pin has to go high and low after a delay of few microseconds. can anybody help me with this ?

Thanks.
 

Hi apha55,
What exactly are you trying to achieve? It may be possible as at 16MHz, each clock = 62.5 ns

Hope this helps.
Tahmid.
 

Not sure about the compiler you are using, but there may be an include file in the library that allows the use of a nop instruction within C. Otherwise you need to insert some assembler routines.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top