I’m using a 16mHz clock and want to make my board as fast as possible. With the code below I toggle a pin continuously and the maximum frequency I can get is 4.1mHz What am I doing wrong??
void main()
{
PLLCON = 0x03; //Activate PLL connect and PLL enable
According to the user manual for the LPC2148, which has fast IO, the fastest you can change IO is around 15.4 MHz when the internal bus is running at 60 MHz (p. 94). The slow IO ports change around 3.5 times slower, and can change at 4.25 MHz. If you’re going for speed, you should definitely step up to one of the better chips (213x or 214x).
I don’t know what processor he’s using, I was just saying the thing about the LPC2148 as an example. He may be using an ARM with fast I/O and the slow speed is all that C will allow. The example in the user manual uses assembly for maximum speed. I was basically just trying to illustrate leon_heller’s point about how slow the I/O is in certain ARMs.
Set the SCS register to 0x03. Take a look at p. 26 in the user manual and you will see that you have to have both bits set to get both of the I/O registers to work with fast I/O (FIO0 and FIO1). This may not fix your problem depending on which register you’re using. If you want to get the 15 MHz switching speed, you’re more than likely going to have to use assembly. Check out the page in the user manual that I referenced in a previous post and it shows the assembly they used to do it.