1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Arm7 Timer0, counter not counting :(

Discussion in 'ARM' started by Smartie, Dec 9, 2011.

  1. Smartie

    Smartie Member

    Joined:
    Oct 2, 2008
    Messages:
    122
    Likes:
    1
    Location:
    Auckland, New Zealand
    Hey Guys,

    I've got Crossworks for Arm installed and talking to a LPC2138 using a Bus Blaster. I've gotten a blinky light working on the new board so the chip is working and I can see all the registers when debugging.

    I've tried to set up a timer interrupt to get an understanding about how the vectored interrupts work but sadly I can't get the timer to trigger an event :(

    when i poked around in the registers, the Timer0Counter (T0TC) does not change over time, the same with with the pre-scale counter (T0PC) but since the pre-scale register (T0PR) isn't set, T0PC shouldn't be changing anyway.

    Here is my timer.cpp:
    Code (text):

    int tmr1cnter = 0;

    void uDelay(int x){
        tmr1cnter = x;
        while(tmr1cnter);
    }


    void __attribute__ ((interrupt)) t0isr(void){
        T0IR |= T0IR_MR0;
        if(tmr1cnter>0){
            tmr1cnter--;
        }
        VICVectAddr = 0;
    }

     void init_timer0(void){
        //--- Timer 0 - interrupt 10 ms
       
        //T0PR = 50; //-- Prescaler = 0
        //T0PC = 0; // Prescaler Counter
        //T0MR0 = 60000 * 10; //clock rate of 60000 * 10ms ?
        T0IR = 0x01;
        T0CTCR &= 0xFC;

        T0MR0 = 599 ; // 1ms
        T0MCR = T0MCR_MR0I | T0MCR_MR0R; //-- bit 0=1 -int on MR0 , bit 1=1 - Reset on MR0
        T0TC = 0x00;
        T0PR = 0x00;
        T0PC = 0x00;

        T0TCR |= T0TCR_Counter_Enable; //-- Timer 0 - run
       
        //VICIntSelect &= ~BIT(4); // ~BIT(VIC_TIMER0);
        VICVectAddr0 = (unsigned)t0isr;//-- Timer 0 int - prioritytop-1
        VICVectCntl0 = 0x24; // VIC_ENABLE | VIC_TIMER0;
        VICIntEnable |= 0x0010; // BIT(VIC_TIMER0);

    }
     
    the usage of the above code is called in main.cpp like this:
    Code (text):

    #include "timer.h"
    #include <targets/LCP21xx.h>
    #include <ctl_api.h>

    // ...

    int main(){
        ctl_global_interrupts_enable();
        init_timer0();

        // ...
       
        while (1)
        {
            uDelay(100);
            IO0CLR = 0x80000000; // Turn the LED off
            uDelay(100);
            IO0SET = 0x80000000; // Turn the LED on

        }
    }
     
    Is anyone able to shed some light onto my situation?
     
    Last edited: Dec 9, 2011
  2. Smartie

    Smartie Member

    Joined:
    Oct 2, 2008
    Messages:
    122
    Likes:
    1
    Location:
    Auckland, New Zealand
    Alright, I had forgotten that I was running the code on the Arm simulator provided by Crossworks.
    So the counter is counting and resetting when it matches with MR0 but now the vectored interrupt will not trigger.

    The register VICRawIntr has flags indicating that an interrupt has been triggered even if they are not enabled and it is showing that Timer0 is flagged.
    So now my next task is to figure out why the VIC isn't working like it should >.>
     
  3. DirtyLude

    DirtyLude Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    1,904
    Likes:
    56
    Location:
    Toronto, Canada
    The LPC2000 Yahoo mailing group may be of some help or Jason here has used them. I've never used the LPC2000 chips, but other ARM7's and they are a pain in the a$$ with all the peripheral juggling. You may need to turn on a peripheral clock. If you can move to the Cortex-M3's you'll be better off.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    Sorry ive been so busy. Ill take a look in a second, i dont have a LPC2138 but ill check code to see if something missing...
     
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    ok need some more info... what speed clock your using?

    also..

    Code (text):
     

    int tmr1cnter = 0;
     
    void uDelay(int x){
        tmr1cnter = x;
        while(tmr1cnter);
    }
    //-- Try this type
    static
    void t0isr(void){
        T0IR |= T0IR_MR0;
        if(tmr1cnter>0){
            tmr1cnter--;
        }
        VICVectAddr = 0;
    }
     
     void init_timer0(void){
        //--- Timer 0 - interrupt 10 ms
        T0IR = 0x01;
            T0CTCR &= 0xFC;
     
        T0MR0 = 599 ; // 1ms
        T0MCR = T0MCR_MR0I | T0MCR_MR0R; //-- bit 0=1 -int on MR0 , bit 1=1 - Reset on MR0
        T0TC = 0x00;
        T0PR = 0x00;
        T0PC = 0x00;
     
        VICVectAddr0 = (unsigned int)t0isr ;//-- Timer 0 int - prioritytop-1 ---->TRY unsigned int
        VICVectCntl0 = 0x24; // VIC_ENABLE | VIC_TIMER0;
        VICIntEnable |= 0x0010; // BIT(VIC_TIMER0);
     
        T0TCR |= T0TCR_Counter_Enable; //-- Timer 0 - run --> START TIMER AFTER SETUP
    }
     
     

Share This Page