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.

can we use delay_us('fraction or decimal value) using CCS

Status
Not open for further replies.

syamin0712

Member level 1
Joined
Jan 2, 2015
Messages
36
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
406
Hi,

I want to generate continuous 20MHz pulse using function delay_us() in ccs.
I used PIC18F4580 and the crystal was 10MHz with PLL. So that, I can get the clock is 40MHz.

I have this code:
/// 20MHz pulse

#include <18F4580.h>
#fuses H4,NOWDT,NOLVP,BROWNOUT,PUT,NOPBADEN
#use delay(clock=40000000)

void main ()
{

while (TRUE)
{

output_high(PIN_B1);

delay_us(1/40); //set 25ns each

output_low(PIN_B1);

delay_us(1/40); //set 25ns each

}

}


When I compile the code; there is no error. However when I burn into PIC and test using oscilloscope, there was no pulse exist.
Does it correct the way I'm wrote my code?
Because when Im tried let say for 500Hz or 5kHz the code was successfull.
Or does it because of the PIC cannot support for too high frequency?
 

This is small portion of code please upload full code so that all register declarations are displayed. Instead use a timer to create pulse that is much accurate method using which you can also get variations in high precision.
 

Hi

This is only and the full code that i used.
I just want to produce the pulse with 20MHz at pin B1.

With this statement:
"Instead use a timer to create pulse that is much accurate method using which you can also get variations in high precision."

Can you suggest or guide which method i can applied?
If there is an example of the coding i"ll appreciate it as a guide for me.
 

Hi,
Please visit this link:https://www.ccsinfo.com/forum/viewtopic.php?t=22467 for Timer tutorial for CCS compiler. I am not much familiar with CCS compiler, so I cannot help you much for coding. To understand pulse generation using timer you need to understand timer operation of PIC and then its easy for coding once you understand it.This is the full code? you need to declare values of registers associated with the port to use it for digital IO as some I/O ports are also multiplexed with ADC, SPI,I2C etc.
 

Even without delay, you can get 40/(5+2) = ~ 5.7MHz output.
You better use CPLD or FPGA for this purpose.
And delay function requeires unsigned int value.
 

PIC18 if runs at 40Mhz means it will have 10 MIPS instruction time (40/4) normally.
So if you try the code below without any delay, you will get to know the maximum time you can get from a PIC.

Code:
while (1)
{
output_high(PIN_B1);
output_low(PIN_B1);
}

and delay_us does not work with fractional, it only needs integer value greater than 1
 

No, instead of change pin state two times, you can just invert it state portb ^= 0xFF; for example.
Faster way is to change state of whole port:
portb = 0x00;
portb = 0xFF;
But you will loose 2 cycles for while loop. So you can just repeat changing state as much as you have a free memory for that. This will give you ~40/2 MHz
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top