Hi,
I'm planning to do PWM and Timer2 with USB feature using PIC18F4550 with crystal of 20MHz.
What I intend to do is to have both PWM and Timer2 interrupt running on 20MHz as in FOSC = 20 MHz.
Attached is the print screen of my settings in configuration bits.
To test whether the code is running at 20MHz or not, i program a simple code to blink the LED ON for 1 second and then OFF for another second and i measure its time by using stopwatch. What i found is the code is running slower compared to the stopwatch.
Below is how i did the blinking code. I put it in a while loop so that the PIC will do nothing else except blinking the LED.
The reason why i did the above testing is to ensure that the PIC is indeed running at 20MHz so that when I do PWM and Timer2, I can use FOSC = 20MHz for the calculation. However, it seems that the PIC is running abit slower than 20MHz and because of that, I'm afraid when I do the PWM and Timer2, the result will be off.. Can somebody pls advice..
Thanks.
I'm planning to do PWM and Timer2 with USB feature using PIC18F4550 with crystal of 20MHz.
What I intend to do is to have both PWM and Timer2 interrupt running on 20MHz as in FOSC = 20 MHz.
Attached is the print screen of my settings in configuration bits.
To test whether the code is running at 20MHz or not, i program a simple code to blink the LED ON for 1 second and then OFF for another second and i measure its time by using stopwatch. What i found is the code is running slower compared to the stopwatch.
Below is how i did the blinking code. I put it in a while loop so that the PIC will do nothing else except blinking the LED.
Code:
// I'm using 20MHz crystal oscillator.
void main(void)
{
InitializeSystem();
while(1)
{
USBTasks(); // USB Tasks
ProcessIO(); // See user\user.c & .h
while (1)
{
PORTD = 0xFF;
Delay10KTCYx(200);
Delay10KTCYx(200);
Delay10KTCYx(100);
PORTD = 0x00;
Delay10KTCYx(200);
Delay10KTCYx(200);
Delay10KTCYx(100);
}
}//end while
}//end main
The reason why i did the above testing is to ensure that the PIC is indeed running at 20MHz so that when I do PWM and Timer2, I can use FOSC = 20MHz for the calculation. However, it seems that the PIC is running abit slower than 20MHz and because of that, I'm afraid when I do the PWM and Timer2, the result will be off.. Can somebody pls advice..
Thanks.