Hallo Leute,
ich habe mir eine Delayfunktion mit dem CT32B0 Timer des ARM LPC1313
geschrieben. Nun habe ich den fall dass es mit 1s, 0.500s, 0.100s
funktioniert, aber z.B. mit 0.0001, 0.00000001 nicht geht, d.h. er
bleibt in meiner while schleife hängen, weil anscheinend kein
interruptflag gesetzt wird. Jetzt habe ich bestimmt einen Fehler drin,
den ich nicht erkenne, evtl. sieht es von euch jemand :-)
Der Timer läuft mit einer 72 MHz Clock und der Prescaler gibt jeden
Takt zum Timer Counter durch.
hier der die init Funktion:
1 | void delay_init()
|
2 | {
|
3 | /* set timer */
|
4 | SYSAHBCLKCTRL_bit.CT32B0 = ONE_C; // PCLK enabled for CT32B0
|
5 | TMR32B0TCR_bit.CE = ZERO_C; // disable counting
|
6 | TMR32B0TCR_bit.CR = ONE_C; // reset timer
|
7 | TMR32B0TCR_bit.CR = ZERO_C;
|
8 | TMR32B0CTCR_bit.CTM = ZERO_C; // set rising PCLK edge timer mode
|
9 |
|
10 | /* set prescale counter */
|
11 | TMR32B0PC = 0; // reset prescale counter
|
12 | TMR32B0PR = 0x00000000; // every PCLK
|
13 |
|
14 | /* set MR0 */
|
15 | TMR32B0MCR_bit.MR0I = ONE_C; // interrupt when MR0 matches TC
|
16 | TMR32B0MCR_bit.MR0R = ONE_C; // TC will be reset if MR0 matches
|
17 | TMR32B0MCR_bit.MR0S = ONE_C; // TC and PC will be stopped
|
18 | }
|
hier die delay funktion:
1 | void delay_CT32B0(float time_delay)
|
2 | {
|
3 | //14ns tick
|
4 | uint32_t count = (uint32_t)((72000000 * time_delay) - 1); // countervalue
|
5 |
|
6 | TMR32B0MR0 = count; // write countervalue to MR0
|
7 | TMR32B0TCR_bit.CE = ONE_C; // enable TC and PC for counting
|
8 |
|
9 | while(TMR32B0IR_bit.MR0INT != ONE_C); // waiting for interrupt
|
10 |
|
11 | TMR32B0IR_bit.MR0INT = ONE_C; // MR0 Interruptflag zurücksetzen
|
12 | }
|
Dann noch eine Frage: Wie kann das Programm ohne Interrupt geschrieben
werden?
Danke im voraus
Gruß Christoph