10 years, 11 months ago.

Can anyone tell me why I cant access this? It doesnt recognise the header file or the identifier.

  1. include "mbed.h"
  2. include "LPC11Uxx.h"

LPC_CTxxBx_Type c;

printf("CR0=%d\n", c.CR0);

2 Answers

10 years, 11 months ago.

The second include isn't required, mbed.h already includes everything you need. Then the easy way to address the register is using the file from your second include at line 643:

LPC_CT16B0->CR0

or

LPC_CT16B0->CR[0]

10 years, 11 months ago.

Error: Identifier "LPC_CT16B0" is undefined in "cameramain.cpp", Line: 88, Col: 1

Error: Identifier "LPC_CT16B0" is undefined in "cameramain.cpp", Line: 86, Col: 1

How can I get to read LPC11Uxx.h ???

It seems to be impossible to make sense of this without access to the .h file and I can see how to get to read those.

Why have you changed the variable name from LPC_CTxxBx to LPC_CT16B0 ?

Because of that line 643 of LPC11Uxx.h (http://mbed.org/users/mbed_official/code/mbed/file/9c8f0e3462fb/TARGET_LPC11U24/LPC11Uxx.h). There are 4 timers: two 16-bit ones, and two 32-bit ones. They all have the same register structure. LPC_CT16B0 is the first of the 16-bit timers. But at line 643 they are all defined.

However they are undefined for you because you don't have the LPC11u24. You need to compile your code for the LPC11u24, but according to your page you only have the LPC1768. So if you actually have an LPC11u24, add it to your compiler and compile for it. If you don't have one you cannot use registers specific to it when you have an LPC1768.

posted by Erik - 05 Dec 2013

Ok, made some progress since last time, however I am still having some problems. My ultimate goal is for the program to detect the rising and falling edges of an incoming pulse and display the value of the timer at that time. For now though it is setup just to show the states of the registers and then run the timer. The program compiles fine but does not print anything to the screen, not even the Hello world statement. I had a look around and found some things i might be missing, these are the lines I have commented out.

A solution to this problem would be very much appreciated, here is my code:

  1. include "mbed.h"

uint32_t a = LPC_TIM2->IR; /*!< (@ 0x40014000) Interrupt Register */ uint32_t b = LPC_TIM2->TCR; /*!< (@ 0x40014004) Timer Control Register */ uint32_t c = LPC_TIM2->TC; /*!< (@ 0x40014008) Timer Counter */ uint32_t d = LPC_TIM2->PR; /*!< (@ 0x4001400C) Prescale Register */ uint32_t e = LPC_TIM2->PC; /*!< (@ 0x40014010) Prescale Counter */

uint32_t f = LPC_TIM2->CCR; /*!< (@ 0x40014028) Capture Control Register */

uint32_t g = LPC_TIM2->CR0; /*!< (@ 0x4001802C) Capture Register. CR 0 */ uint32_t h = LPC_TIM2->CR1; /*!< (@ 0x40018030) Capture Register. CR 1 */

uint32_t i = LPC_TIM2->CTCR; /*!< (@ 0x40014070) Count Control Register */

int main() { printf("hello world\n\r");

  1. define SET_TCR 0x0001
  2. define SET_IR 0x0001

NVIC_SetPriority(TIMER2_IRQn, (uint32_t)mytTim0Handler); NVIC_DisableIRQ(TIMER3_IRQn); NVIC_EnableIRQ(TIMER2_IRQn); LPC_TIM2->TCR = SET_TCR; LPC_TIM2->IR = SET_IR;

LPC_PINCON->PINSEL0 |= (1<<8) | (1<<9) | (1<<10) | (1<<11); printf("after %i",LPC_PINCON->PINSEL3);

printf("IR = %i\n\r", a); printf("TCR = %i\n\r", b); printf("TC = %i\n\r", c); printf("PR = %i\n\r", d); printf("PC = %i\n\r", e); printf("CCR = %i\n\r", f); printf("CR0 = %i\n\r", g); printf("CR1 = %i\n\r", h); printf("CTCR = %i\n\r", i);

while(1){ printf("TCR = %i\n\r", b); uint32_t c = LPC_TIM2->TC; /*!< (@ 0x40014008) Timer Counter */ uint32_t l = LPC_TIM2->CR0;

printf("TC = %i\n\r", c); printf("CR0 = %i\n\r", g);

wait(1); } }

posted by Glen Armstrong 13 Dec 2013

First of all put your code between code tags (<<code>> and <</code>>), as you can see now it is pretty much unreadable, and also all your comments are gone.

Second, what kind of accuracy/speed do you need? As in, isn't InterruptIn + Timer from mbed lib not enough?

Point 3, if it doesn't print even the hello world, start deleting (or commenting out) stuff until it does print that. Then figure out what was responsible for it.

posted by Erik - 13 Dec 2013

Sorry I'm new to this. Initially it worked with interruptIn however it gave an accuracy of +-1ms which isn't good enough and also it would sometimes miss a falling edge and give the time between the rising edge and the next falling edge, giving out a large number.

#include "mbed.h"


        uint32_t a = LPC_TIM2->IR;                         /*!< (@ 0x40014000) Interrupt Register      */
        uint32_t b = LPC_TIM2->TCR;                        /*!< (@ 0x40014004) Timer Control Register  */
        uint32_t c = LPC_TIM2->TC;                         /*!< (@ 0x40014008) Timer Counter        */
        uint32_t d = LPC_TIM2->PR;                         /*!< (@ 0x4001400C) Prescale Register    */
        uint32_t e = LPC_TIM2->PC;                         /*!< (@ 0x40014010) Prescale Counter  */

        uint32_t f = LPC_TIM2->CCR;                        /*!< (@ 0x40014028) Capture Control Register */

        uint32_t g = LPC_TIM2->CR0;                /*!< (@ 0x4001802C) Capture Register. CR 0 */
        uint32_t h = LPC_TIM2->CR1;                /*!< (@ 0x40018030) Capture Register. CR 1 */

        uint32_t i = LPC_TIM2->CTCR;                       /*!< (@ 0x40014070) Count Control Register */
   

int main() {
printf("hello world\n\r");

#define SET_TCR 0x0001
#define SET_IR 0x0001

//NVIC_SetPriority(TIMER2_IRQn, (uint32_t)mytTim0Handler);
 NVIC_DisableIRQ(TIMER3_IRQn);
 NVIC_EnableIRQ(TIMER2_IRQn);
LPC_TIM2->TCR = SET_TCR;
LPC_TIM2->IR = SET_IR;

LPC_PINCON->PINSEL0 |= (1<<8) | (1<<9) | (1<<10) | (1<<11);
printf("after %i",LPC_PINCON->PINSEL3);


    printf("IR = %i\n\r", a);
    printf("TCR = %i\n\r", b);
    printf("TC = %i\n\r", c);
    printf("PR = %i\n\r", d);
    printf("PC = %i\n\r", e);
    printf("CCR = %i\n\r", f);
    printf("CR0 = %i\n\r", g);
    printf("CR1 = %i\n\r", h);
    printf("CTCR = %i\n\r", i);



while(1){
    printf("TCR = %i\n\r", b);
        uint32_t c = LPC_TIM2->TC;                         /*!< (@ 0x40014008) Timer Counter        */
        uint32_t l = LPC_TIM2->CR0;
        
        
    printf("TC = %i\n\r", c);
    printf("CR0 = %i\n\r", g);

        wait(1);
    }
}
posted by Glen Armstrong 13 Dec 2013
  • line 25 and 26 should also be commented out
posted by Glen Armstrong 13 Dec 2013

With InterruptIn you should get ALOT better resolution than that. It has a significant delay (although nowhere near 1ms), but that should be a pretty much fixed delay.

Anyway if it doesn't actually send the first printf, either try disabling stuff until it does send it, and/or try blinking an LED a few times. It might be that your complete code doesn't start for some reason.

posted by Erik - 13 Dec 2013

I included an led as you suggested and commented out a lot of my code. The problem seems to be with Timer2 as when the Tim2 lines are commented out it runs fine, however when I include a timer2 line the program doesnt run. I have tried it with Timer0 and it works fine, however I want to send input pulses via one of the DIPs and looking at the schematic, pins 40 and 43 on the IC6 which control cap0 do not go to a DIP. Is there any reason why Timer2 shouldnt work? Or any way for me to set this up with Timer0?

#include "mbed.h"

DigitalOut led(LED1);


        uint32_t b = LPC_TIM2->TCR;                        /*!< (@ 0x40014004) Timer Control Register  */
   //     uint32_t c = LPC_TIM2->TC;                         /*!< (@ 0x40014008) Timer Counter        */


   //     uint32_t g = LPC_TIM2->CR0;                /*!< (@ 0x4001802C) Capture Register. CR 0 */

   

int main() {


        led = 1;
        wait(0.2);
        led = 0;
        wait(0.2);
    
printf("\n\r");
printf("hello world\n\r");

#define SET_TCR 0x0001
#define SET_IR 0x0001

//NVIC_SetPriority(TIMER2_IRQn, (uint32_t)mytTim0Handler);
 //NVIC_DisableIRQ(TIMER3_IRQn);
 //NVIC_EnableIRQ(TIMER2_IRQn);
 
printf("hello world1\n\r");
//LPC_TIM2->TCR = SET_TCR;
printf("hello world2\n\r");
//LPC_TIM2->IR = SET_IR;
printf("hello world3\n\r");
LPC_PINCON->PINSEL0 |= (1<<8) | (1<<9) | (1<<10) | (1<<11);
printf("after %i",LPC_PINCON->PINSEL0);

printf("hello world4\n\r");

    printf("TCR = %i\n\r", b);
  //  printf("TC = %i\n\r", c);

//    printf("CR0 = %i\n\r", g);




//while(1){
 //   printf("TCR = %i\n\r", b);
  //      uint32_t c = LPC_TIM2->TC;                         /*!< (@ 0x40014008) Timer Counter        */
   //     uint32_t l = LPC_TIM2->CR0;
        
        printf("1\n\r");
 //   printf("TC = %i\n\r", c);
  //  printf("CR0 = %i\n\r", g);

        wait(1);
        
  //  }
}
posted by Glen Armstrong 16 Dec 2013

Ah I think I know it: I believe when writing a register it expects a response (at least thats the only thing I can think of which results in the behavior you get, and which I have also seen with other stuff). This is done internally, but it does need to happen. Problem: It won't happen, since you forgot to clock your timer, which causes your program to halt.

Timer two is by default disabled. To enable it:

LPC_SC->PCONP |= 1<<22;

(Timer 0 is enabled by default, so that did work).

posted by Erik - 16 Dec 2013

I tried putting in your code but it had no effect on the program. Could you perhaps show me all the code including the syntax I need to run TIMER2? Because at the minute i'm kind of just poking around in the dark! I have spent a good deal of time looking at the user manual but i'm still not sure what I need to do.

posted by Glen Armstrong 16 Dec 2013

I don't have all that code since I haven't worked on this. You did put in that code before accessing anything related to timer2?

Which might help you is this search result: https://mbed.org/users/geotec/code/PulseCounter/file/0eb01612bcb2/PulseCounter.cpp, he also uses Timer 2, and indeed first thing he does is enabling the power to it.

posted by Erik - 16 Dec 2013