Generating Perfect Delay without using timers Code and Proteus Simulation

            This post is all about generating perfectly timed delay without using timers plus Proteus Simulation is also given. You may download code and simulation as well. I am using MPLAB X IDE and C30 Compiler for 16bit PIC or DsPIC microcontrollers.

Before I start with the coding and Proteus simulation you should know the oscillator frequency on which your controller is running or you should know about Machine Cycle. By default PIC24 and DsPIC Machine Cycle is 2 which is written in datasheet until and unless you use divisors to further divide this frequency so it’s better you should know Instruction Cycle clock.
            So the formula is written in datasheet
                        FCY = Instruction cycle clock (frequency).
                        FOSC = oscillator frequency.

            Now let’s start. I am using 10MHz crystal and using default Instruction cycle so FCY = 5Mhz. 

Proteus Circuit.

            The above figure shows that I am using PortB PIN 7. Which will toggle its state after every 500milliseconds (500ms or half a second). You can increase the delay by increasing the value passed in __delay_ms() function. This value will generate the delay in millisecond. Furthermore this before using this function you should include its header file <libpic30.h>.

Code in MPLAB X C30 compiler
Code in MPLAB X C30 compiler

And now.

Reading Suggestions:

Downloads code + Proteus      

You can download Code and Proteus Simulation Click here


Popular posts from this blog

Defining code regions in MPLAB X IDE

Digital AC voltmeter Schematic + Code + Proteus Simulation

Automatic Streetlight control using LDR and PIC (Code + Proteus Simulation)