I am new to ARM and I am trying to produce 1 second delay using timer 0 in LPC2148. But in debug session in Keil, it is giving delay of 4 seconds with 15MHz and 5 seconds with 12 MHz. What is the issue ?
Here is my code.
#include <lpc214x.h> int main() { IODIR0 = 1; // P0.0 is output pin IOSET0 = 1; // P0.0 is high T0PR = 15000000 - 1; T0TC = T0PC = 0; T0TCR = 1; // start do { while(T0TC == 0); T0TC = 0; IOCLR0 = 1; // P0.0 is low while(T0TC == 0); T0TC = 0; IOSET0 = 1; // P0.0 is high } while(1); }
Real hardware or simulator?
Toggling pin halves frequency observed at GPIO.
Not sure of merit of setting counter to zero when already supposedly zero.
Find other examples. Check internal clock, perhaps there is a means to export to a pin?
In simulation. In keil as well as proteus, both are giving 4/5 seconds of delay. What I am thinking is I have configured frequency to 12MHz and Vpbdiv by default is 0. So it may be diving the frequency by 4. Is it possible ? but PLL configurations are default.(Set by startup code).
kamalpancholi said:it may be diving the frequency by 4. Is it possible ?
What does the chip documentation tell you?
I don't know. I'd just unpack the PLL settings and see what the expectations are rather than guess.
The thing should clock off PCLK, but it's not a part I'm using, and I don't suspect the simulator is cycle accurate for things outside the core.
Perhaps you should invest is some current hardware, the ARM7TDMI-S is pretty antiquated at this point, given the other options I'd have to think the market for NXP LPC2148 programming skills is tending to zero.
Westonsupermare Pier said:Perhaps you should invest is some current hardware
Indeed.
kamalpancholi - Not least because most current chips these days are available with low-cost dev boards that include a debug probe - so you can throw away all the doubts & uncertainties of simulators, and just use the actual hardware!
Westonsupermare Pier said: I don't suspect the simulator is cycle accurate for things outside the core.
I haven't still bought any hardware. I am just new to ARM controllers so I am starting with the very basic one
kamalpancholi said:I am just new to ARM controllers
All the more reason to start with something up-to-date!
Again, it is certainly worth getting one of the many low-cost dev boards that includes a debug probe - far better than messing about with simulators!
Most manufacturers have some beginner's tutorials based on these boards.
Keil's own getting started stuff: http://www2.keil.com/mdk5/learn
View all questions in Keil forum