This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not working

in the simulation program running smoothly, but when the diwnload to the target is not working as it should. .

The following source code

#include <LPC214x.H>

void delay(unsigned int lama)
{ /* My PCLK of Timer0 is 12Mhz */
unsigned int d;
for(d=0;d<lama;d++){
T0PR = 9999; // Prescale Register = 9999
T0MR0 = 1200; // Match Register = 900
T0MCR = 0x00000004; // Stop on MR0: the TC and PC will be stopped // and TCR[0] will be set to 0 if MR0 matches the TC.
T0TCR = 0x02; // Counter Reset
T0TCR = 0x01; // Counter Enable
while(T0TC != T0MR0);
T0TC = 0; // TC kembali ke 0
} }

void delay_ms(unsigned int lama_1)
{ /* My PCLK of Timer0 is 12Mhz */
unsigned int d;
for(d=0;d<lama_1;d++){
T0PR = 999; // Prescale Register = 9999
T0MR0 = 12; // Match Register = 900
T0MCR = 0x00000004; // Stop on MR0: the TC and PC will be stopped // and TCR[0] will be set to 0 if MR0 matches the TC.
T0TCR = 0x02; // Counter Reset
T0TCR = 0x01; // Counter Enable
while(T0TC != T0MR0);
T0TC = 0; // TC kembali ke 0
}

}

void delay_ns(unsigned int lama_2)
{ /* My PCLK of Timer0 is 12Mhz */
unsigned int d;
for(d=0;d<lama_2;d++){
T0PR = 1; // Prescale Register = 9999
T0MR0 = 12; // Match Register = 900
T0MCR = 0x00000004; // Stop on MR0: the TC and PC will be stopped // and TCR[0] will be set to 0 if MR0 matches the TC.
T0TCR = 0x02; // Counter Reset
T0TCR = 0x01; // Counter Enable
while(T0TC != T0MR0);
T0TC = 0; // TC kembali ke 0
}

}

int main(void)
{

unsigned int i;
IODIR1 = 0x00FF0000; // set all ports to output

while(1)
{

for(i=0;i<4;i++){
IOSET1 = 0x00010000; //set output pins
delay_ns(200);
IOCLR1 = 0x00010000; //clear output pins
delay_ns(200);
}

delay_ns(19800);

}
}

please enlightenment?!

Parents
  • 1) Why didn't you bother to tell some more information than just saying that it doesn't work? Haven't you done any debugging to narrow down what is wrong?

    2) Why do you reinitialize the timer for every delay call? You can keep the timer free-running and just look at the counter values.

    3) You perform an exact compare for the timer loop. What makes you so sure that your comparison code will manage to catch every single tick of the timer? What if you miss the specific tick - then the timer needs 4 billion more ticks before you get a second chance.

    4) You have a function that claims to set up delays in ns resolution - but what errors? How many nanoseconds does it take to initialize the timer before you can even start with the actual time-keeping?

    5) You want to toggle some processor pins. Why not select processor pins that can be directly toggled by the timer hardware, without any intervention from the software? That would give you pin toggles without the latency and measurement errors from all the clock cycles spent between each timer delay.

    6) Do you really think this is a problem for the forum, and not something you should have been able to fight on your own? Programming is to a big part a question of figuring out a good design. And the next big part is to debug the code. Actually writing in the source code statements is the tiny part. Are you spending any time with design and debugging, or just spending time writing source code?

Reply
  • 1) Why didn't you bother to tell some more information than just saying that it doesn't work? Haven't you done any debugging to narrow down what is wrong?

    2) Why do you reinitialize the timer for every delay call? You can keep the timer free-running and just look at the counter values.

    3) You perform an exact compare for the timer loop. What makes you so sure that your comparison code will manage to catch every single tick of the timer? What if you miss the specific tick - then the timer needs 4 billion more ticks before you get a second chance.

    4) You have a function that claims to set up delays in ns resolution - but what errors? How many nanoseconds does it take to initialize the timer before you can even start with the actual time-keeping?

    5) You want to toggle some processor pins. Why not select processor pins that can be directly toggled by the timer hardware, without any intervention from the software? That would give you pin toggles without the latency and measurement errors from all the clock cycles spent between each timer delay.

    6) Do you really think this is a problem for the forum, and not something you should have been able to fight on your own? Programming is to a big part a question of figuring out a good design. And the next big part is to debug the code. Actually writing in the source code statements is the tiny part. Are you spending any time with design and debugging, or just spending time writing source code?

Children