EmbeddedRelated.com
Forums

Timer Match on LPC2138

Started by allendeng881028 August 26, 2011
I wrote the code to a pin toggle when timer match, but it seems the code doesnt work. Any idea what's the problem?

void ping(void){

T1MR2 = 200;
T1MCR |= 1<<7;
T1EMR |= ((1<<4) | (1<<5));
T1TCR |= 0x02;
T1TCR |= 0x01;

}

Cheers,
Allen

An Engineer's Guide to the LPC2100 Series

when T1TCR |= 0x02; the counter is held in a reset state, do you change it to 0 so that the timer can count?
Have you set the MAT1.2 function to a pin

Check ARMwizard (http://alexan.edaboard.eu/), you will probably do this settings easier

Alex
On 08/26/2011 10:24 AM, allendeng881028 wrote:

> I wrote the code to a pin toggle when timer match, but it seems the code doesnt work. Any idea what's the problem?
>
> void ping(void){
>
> T1MR2 = 200;
> T1MCR |= 1<<7;
> T1EMR |= ((1<<4) | (1<<5));
> T1TCR |= 0x02;
> T1TCR |= 0x01;
>
> }
>
> Cheers,
> Allen

yea I set the pin to MAT1.2 but I didn't change the T1TCR to 0, so setting the T1TCR to zero trigger the counter?
At 2011-08-26 16:47:57,Alexan_e wrote:
when T1TCR |= 0x02; the counter is held in a reset state, do you change it to 0 so that the timer can count?
Have you set the MAT1.2 function to a pin

Check ARMwizard (http://alexan.edaboard.eu/), you will probably do this settings easier

Alex

On 08/26/2011 10:24 AM, allendeng881028 wrote:

> I wrote the code to a pin toggle when timer match, but it seems the code doesnt work. Any idea what's the problem?
>
> void ping(void){
>
> T1MR2 = 200;
> T1MCR |= 1<<7;
> T1EMR |= ((1<<4) | (1<<5));
> T1TCR |= 0x02;
> T1TCR |= 0x01;
>
> }
>
> Cheers,
> Allen
>
>
If you check the datasheet it says
T1TCR bit 0 = Counter Enable
When one, the Timer Counter and Prescale Counter are 0 enabled for counting. When zero, the counters are disabled.
T1TCR bit 1 = Counter Reset
When one, the Timer Counter and the Prescale Counter 0 are synchronously reset on the next positive edge of PCLK.
*The counters remain reset until TCR[1] is returned to zero.*
so unless you set bit 1 to 0 the timer will never count

Alex

On 08/26/2011 01:54 PM, 邓登 wrote:

> yea I set the pin to MAT1.2 but I didn't change the T1TCR to 0, so setting the T1TCR to zero trigger the counter?
> At 2011-08-26 16:47:57,Alexan_e wrote:
> when T1TCR |= 0x02; the counter is held in a reset state, do you change it to 0 so that the timer can count?
> Have you set the MAT1.2 function to a pin
>
> Check ARMwizard (http://alexan.edaboard.eu/), you will probably do this settings easier
>
> Alex
>
> On 08/26/2011 10:24 AM, allendeng881028 wrote:
>
>> I wrote the code to a pin toggle when timer match, but it seems the code doesnt work. Any idea what's the problem?
>>
>> void ping(void){
>>
>> T1MR2 = 200;
>> T1MCR |= 1<<7;
>> T1EMR |= ((1<<4) | (1<<5));
>> T1TCR |= 0x02;
>> T1TCR |= 0x01;
>>
>> }
>>
>> Cheers,
>> Allen