mec WROTE:Hi Allen,
May i know what simulator are you using? Just curious to know.
chaos64 WROTE:How can I use the hex file if I'm running at 20MHz? I would need to edit the code then run the program...
//=============================================================================
// Configuration Bits
//=============================================================================
#pragma config PLLDIV = 5 // 20 MHz crystal
#pragma config CPUDIV = OSC1_PLL2 //
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS //
#pragma config FCMEN = OFF //
#pragma config IESO = OFF //
#pragma config PWRT = OFF //
#pragma config BOR = OFF //
#pragma config VREGEN = ON // USB Voltage Regulator disabled
#pragma config WDT = OFF //
#pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config CCP2MX = OFF // CCP2 input/output is multiplexed with RC1
#pragma config LVP = OFF // Single-Supply ICSP disabled
#pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming Port disabled
#pragma config XINST = OFF // Extended Instruction Set
/********************************************************************
* Please copy this routine to userprogram.c, then uncomment it */
/********************************************************************
* Function Name: Delay_1msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 1ms (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (1ms * 48MHz) / 4 *
* Cycles = 12,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 12,000. *
********************************************************************/
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(11);
Delay10TCYx(96);
Nop();
Nop();
Nop();
Nop();
Nop();
t++;
}
} //End of Delay_1msX
//=============================================================================
// Configuration Bits
//=============================================================================
#pragma config OSC = HS // HS oscillator
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF // Oscillator Switchover mode disabled
#pragma config PWRT = OFF // PWRT disabled
#pragma config BOREN = OFF // Brown-out Reset disabled in hardware and software
#pragma config WDT = OFF // WDT disabled (control is placed on the SWDTEN bit)
#pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config CCP2MX = PORTC // CCP2 input/output is multiplexed with RC1
#pragma config LVP = OFF // Single-Supply ICSP disabled
#pragma config XINST = OFF // Extended Instruction Set
ABSF WROTE:Any one care to explain how PIC18F PLL clock works ? And how is 1 mS delay generated ?
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(4);
Delay10TCYx(95);
Nop();
// Nop();
// Nop();
// Nop();
// Nop();
t++;
}
}//End of Delay_1msX
kl84 WROTE:Usually I do like this:
Go to Debugger > Select Tool > MPLAB SIM. Then Debugger > Settings > 20MHz and Debugger > StopWatch. I call the delay function in my main program and place breakpoints before and after this function call line. Build the program and run debugger. The debugger will cause the program to stop at first breakpoint. Zero the StopWatch, run the debugger again. When it stops at 2nd breakpoint, you will get the time Instruction Cycle and Time used to execute the delay function.
This is what I get to yield 1msec delay:
CODE: SELECT ALL
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(4);
Delay10TCYx(95);
Nop();
// Nop();
// Nop();
// Nop();
// Nop();
t++;
}
}//End of Delay_1msX
I have to comment some Nop(); to get the closest value to 1 msec. Delay1KTCYx(); and Delay10TCYx(); are C18 libraries functions and Nop(); does nothing for one instruction cycle.
My StopWatch shows Instruction Cycles = 5001 and Time (mSecs) = 1.000200. You can have a try to get the correct 100 msec delay for your processor and crystal frequency.
Return to PIC Development Tool
Users browsing this forum: No registered users and 21 guests