EmbDev.net

Forum: ARM programming with GCC/GNU tools LPC2148 Pulse width demultiplexer using CAP0.0


Author: Noel Le Moult (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello,

I have an Logomatic-v23 board from Sparkfun electronics. I want to use 
an ADXL213AE accelerometer.

The ADXL send his PWM output value and i want to capture it using the 
CAP0.0 input of the LPC2148. Unfortunately I have tried the following 
code and it don't want to acquire the value.

Initialization :
//Enable Interrupts
VPBDIV=1;    // Set PCLK equal to the System Clock
VICIntSelect = ~(UART1_INT | RTC_INT | TIMER0_INT);
VICVectCntl0 = 0x20 | 7;      //Set up the UART1 interrupt
VICVectAddr0 = (unsigned int)ISR_RxData1;
VICVectCntl1 = 0x20 | 13;      //Set up the RTC interrupt
VICVectAddr1 = (unsigned int)ISR_RTC;
VICVectCntl2 = 0x20 | 4;      //Timer 0 Interrupt
VICVectAddr2 = (unsigned int)ISR_Timer0;

//TIMER0 setup
T0TCR = 0x02;       // TIMER0 Disable; reset T0TC & T0PC
T0PR = 0x00000000;  // Reset T0PR
T0CTCR = 0x00;      // Timer Mode: every rising PCLK edge
T0CCR = 0x06;       // Capture on CAPn.0 falling edge and Interrupt on CAPn.0 event
static void ISR_Timer0(void)
{
    //Interrupt Code Here
    T0TCR = 0x02;       // TIMER0 Disable; reset T0TC & T0PC
    T0PR = 0x00000000;  // Reset T0PR
  
    YPacc = T0CR0;     //Get accelerometer captured value
    
    T0IR = 0xFF;       //Clear the timer interrupt
    T0TCR = 0x01;      // TIMER0 Enable 
    VICVectAddr =0;    //Update the VIC priorities
}

Main code :
rprintf_devopen(putc_serial0); //Init rprintf
rprintf("ADXL2148 Accelerometer Yp raw data :\n\r");

VICIntEnable |= TIMER0_INT;  //Enable Timer0 Interrupts
T0TCR = 0x01;       // TIMER0 Enable 

while( 1 )
{
    rprintf("T0CR0:%i\n\r",T0TC);
}

Output on Hyperterminal :
ADXL2148 Accelerometer Yp raw data :
T0CR0:369396
T0CR0:139755
T0CR0:271646
T0CR0:539757
T0CR0:311754
And the value is never the same...

Does anybody could help me to find my problem?

Author: Noel Le Moult (Guest)
Posted on:

Rate this post
0 useful
not useful
I have made a mistake in my previous post :

Main code should be :
rprintf_devopen(putc_serial0); //Init rprintf
rprintf("ADXL2148 Accelerometer Yp raw data :\n\r");

VICIntEnable |= TIMER0_INT;  //Enable Timer0 Interrupts
T0TCR = 0x01;       // TIMER0 Enable 

while( 1 )
{
    rprintf("T0CR0:%i\n\r",YPacc);
}

And the result output is now :
ADXL2148 Accelerometer Yp raw data :
T0CR0:4326756
T0CR0:4325926
T0CR0:4324216
T0CR0:4324036
T0CR0:4326626
T0CR0:4324236

It seems working now.

Thanks

Author: Noel Le Moult (Guest)
Posted on:

Rate this post
0 useful
not useful
Ok, now it detect falling edge of pwm signal but it always capture the 
total period and not the duty cycle of my signal.

I need to capture the duty cycle to have a correct value of my ADXL.

Author: Noel Le Moult (Guest)
Posted on:

Rate this post
0 useful
not useful
I have solved my problem. Here is my personal solution to get the duty 
cycle of the original pwm incoming signal:

Main code :
rprintf_devopen(putc_serial0); //Init rprintf
rprintf("ADXL2148 Accelerometer Yp raw data :\n\r");

while( 1 )
{
    VICIntEnable |= TIMER0_INT; // Enable Timer0 Interrupts
    T0TCR = 0x01;               // TIMER0 Enable
    delay_ms(20);               // Do some acquisition
    T0TCR = 0x00;               // TIMER0 Disable
    VICIntEnClr |= TIMER0_INT;  // Stop Timer0 Interrupts

    result = T1/((T1+T2)/100);  // Duty cycle calculation in percent

    if( (result > (oldresult+1)) || (result < (oldresult-1)) ) // If detect movement
    {
        i=100;
        rprintf("%d ", result );
    }

}


Interrupt section :
static void ISR_Timer0(void)
{
    //Interrupt Code Here
    T0TCR = 0x02;       // TIMER0 Disable; reset T0TC & T0PC
    T0PR = 0x00000000;  // Reset T0PR

    if(state)
    {
        T1 = T0CR0;
        T0CCR = 0x06;   // Capture on CAPn.0 falling edge and Interrupt on CAPn.0 event
        state = 0;
    }
    else
    {
        T2 = T0CR0;
        T0CCR = 0x05;   // Capture on CAPn.0 rising edge and Interrupt on CAPn.0 event
        state = 1;
    }

    T0IR = 0xFF;       //Clear the timer interrupt
    T0TCR = 0x01;      // TIMER0 Enable

    VICVectAddr =0;    //Update the VIC priorities
}

It should be working, but adjust the "delay_ms(20);" in the main code 
section according to the period of your pwm signal.

Author: parth kalaria (er_parth92)
Posted on:

Rate this post
0 useful
not useful
hello sir,

i am also try to access capture mode in timer0,but can't get the 
output..i am try to calculate frequency using this mode.. plz send ur 
code so i can get some idea..

thank you....

Author: Nik (Guest)
Posted on:

Rate this post
0 useful
not useful
I can print anything with

rprintf("T0CR0:%i\n\r",T0TC); !!!

rprintf is not possible for uVision 4 ?
Can you tell me how I can use this software for rotary encoder

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.