Hello all im stuck yet again on this dsPIC stuff heh this time i want to use a 10Mhz crystal on OSC1:2 and want to turn it to 80Mhz using the PLL on chip. Now i have 2 questions...
1. Will this give me 20MIPS ?
2. If so why doesnt this delay for 1 second ? When i run this code it takes 12 seconds for the led to toggle.
The for loop does not execute just a single instruction per run through the loop. Look at the ASM output of the for loop so you can count how many instructions are actually used, then divide your delay number by that many.
In other words, if there are four instructions in the main for loop, then you would only use 5000000 as the delay count. That assumes all instructions are only 1 cycle execution times, which most are.
EDIT: You might have to write your delay loop in ASM, since I think it will be much more precise than a for loop.
define FCY 1000000UL
#include <libpic30.h>
int main()
{
/* at 1MHz, these are equivalent */
__delay_us(1000);
__delay32(1000);
}
This function relies on a user-supplied definition of FCY to represent the instruction clock frequency. FCY must be defined before header file libpic30.h is included. The specified delay is converted to the equivalent number of instruction cycles and passed to __delay32(). If FCY is not defined, then __delay_us() is declared external, causing the link to fail unless the user provides a function with that name.
It must generate the delay based upon the internal clock, which would be 80MHz. I cant find any info about how the delay is generated, and what timing it uses.