I am working on a circuit board for my science fair project right now, and am having some trouble with c18 delays. I can call the delay functions and the code compiles fine, but when I check the signal with my oscilloscope, the delays aren't the length they should be. According to the datasheet for the 18f4320 (the chip i am using) each instruction cycle is 100ns, so If I delay 10 instruction cycles it should be 1 microsecond, but for some reason I suspect it has to do with the oscillator being improperly configured, but I have it set to HSPLL. If anyone has any suggestions they would be greatly appreciated!
#include <p18f4320.h>
#include <delays.h>
#include <adc.h>
#pragma config OSC = HSPLL /* Sets the oscillator mode to HSPLL */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#pragma config DEBUG = OFF /* Compiles without extra debug code */
void MvServo (unsigned char, int);
void main (void)
{
LATB=0x00;
TRISB=0x00;
while(1)
{
MvServo(0xFF, 1);
}
}
void MvServo (unsigned char bports, int inst)
{
int i;
LATB=0x00;
TRISB=0x00;
for(i=0; i<100; i++)
{
LATB=bports;
Delay10TCYx(inst);
LATB=0x00;
Delay10TCYx(20-inst);
}
return;
}