speaking of the LPC210x...

Started by warm38spl May 23, 2011
I was working on a project with a LPC2106 until I hit a snag.

It seems that the 2101,2102,2103 have a complete External Interrupt setup (like the LPC213x), but the 2106 has a half-baked one. The User Manual on the 2106 does not have the EXTMODE and EXTPOLAR registers. The 2106 only has EXTINT and EXTWAKE.

I was counting on the EXTMODE/EXTPOLAR to be able to detect rising edges so that I can get duty cycle info on an incoming square wave.

Any suggestions on how to capture the duty cycle and period on an incoming square wave without the rising edge external interrupts. The square wave can vary 10-50 Hz and duty cycle 49-51%.

I got spoiled on the 2138.

wade

An Engineer's Guide to the LPC2100 Series

My user manual has all four registers

LPC2104/2105/2106 User manual
Rev. 02 - 8 April 2009

Alex

----- Original Message -----
From: warm38spl
To: l...
Sent: Monday, May 23, 2011 4:53 PM
Subject: [lpc2000] speaking of the LPC210x...

I was working on a project with a LPC2106 until I hit a snag.

It seems that the 2101,2102,2103 have a complete External Interrupt setup (like the LPC213x), but the 2106 has a half-baked one. The User Manual on the 2106 does not have the EXTMODE and EXTPOLAR registers. The 2106 only has EXTINT and EXTWAKE.

I was counting on the EXTMODE/EXTPOLAR to be able to detect rising edges so that I can get duty cycle info on an incoming square wave.

Any suggestions on how to capture the duty cycle and period on an incoming square wave without the rising edge external interrupts. The square wave can vary 10-50 Hz and duty cycle 49-51%.

I got spoiled on the 2138.

wade
I have an older manual. But I have a LPC2106.h file that also omits those. I stole the definitions from a LPC2103.h file, but I could not get the registers to act like they were there. (???)
I just found (I guess I didnt have the search set correctly last time I tried) and downloaded the same User Manual that you have and yup, there they are... now if they would only work.

I set up the External Interrupts like I did with the LPC2138 (the LPC2138 version works just fine). However, with the input signal held at ground, EINT0 stayed in a constant interrupt state and would not let anything else run because it went right back there as soon as it came out. That sure acts like they aren't there, or that the definitions are a lot different than the 2103 or 2138.

From LPC2106.h
#define EXTMODE (*(volatile unsigned char *)0xE01FC148)
#define EXTMODE_EINT0_Lvl 0x00U
#define EXTMODE_EINT0_Edge 0x01U
#define EXTMODE_EINT1_Lvl 0x00U
#define EXTMODE_EINT1_Edge 0x02U
#define EXTMODE_EINT2_Lvl 0x00U
#define EXTMODE_EINT2_Edge 0x04U

#define EXTPOLAR (*(volatile unsigned char *)0xE01FC14C)
#define EXTPOLAR_EINT0_LoFall 0x00U
#define EXTPOLAR_EINT0_HiRise 0x01U
#define EXTPOLAR_EINT1_LoFall 0x00U
#define EXTPOLAR_EINT1_HiRise 0x02U
#define EXTPOLAR_EINT2_LoFall 0x00U
#define EXTPOLAR_EINT2_HiRise 0x04U

From main.c ExtIntInit()
PINSEL0 &= ~(PINSEL0_P0_15MASK); // clear out old functions
PINSEL1 &= ~(PINSEL1_P0_16MASK); // clear out old functions
PINSEL0 |= PINSEL0_P0_15EINT2; // new function
PINSEL1 |= PINSEL1_P0_16EINT0; // new function
EXTMODE = EXTMODE_EINT0_Edge + EXTMODE_EINT2_Edge; // All edge sensitive =0x05
EXTPOLAR = EXTPOLAR_EINT0_HiRise + EXTPOLAR_EINT2_HiRise; // all rising edge =0x05
EXTINT = EXTINT_EINT0 + EXTINT_EINT2; // clear interrupt EINT0+2

My understanding is that EXTMODE defaults are LEVEL and EXTPOLAR is LOW. If I cannot change them then a LOW on EINT0 will cause an interrupt and keep interrupting (which is exactly as I saw). So a HIGH will not allow an interrupt to occur. One thing I did not try (I just now thought of it), was to hold the signal high and verify that the interrupts would not occur. This would give a solid evidence that the registers do not exist (at least on the chip versions on the 3 boards that I have which all act the same).

OK, I'll go back and try a pullup on the pins and see if I get NO interrupts on those pins then put it low and watch for interrupts.

In the event that my chips do not have the EXTMODE/EXTPOLAR registers functional, how would I go about getting the period and duty cycle?

wade

--- In l..., "Alexan_e" wrote:
>
> My user manual has all four registers
>
> LPC2104/2105/2106 User manual
> Rev. 02 - 8 April 2009
>
> Alex
>
> ----- Original Message -----
> From: warm38spl
> To: l...
> Sent: Monday, May 23, 2011 4:53 PM
> Subject: [lpc2000] speaking of the LPC210x...
>
> I was working on a project with a LPC2106 until I hit a snag.
>
> It seems that the 2101,2102,2103 have a complete External Interrupt setup (like the LPC213x), but the 2106 has a half-baked one. The User Manual on the 2106 does not have the EXTMODE and EXTPOLAR registers. The 2106 only has EXTINT and EXTWAKE.
>
> I was counting on the EXTMODE/EXTPOLAR to be able to detect rising edges so that I can get duty cycle info on an incoming square wave.
>
> Any suggestions on how to capture the duty cycle and period on an incoming square wave without the rising edge external interrupts. The square wave can vary 10-50 Hz and duty cycle 49-51%.
>
> I got spoiled on the 2138.
>
> wade
>

Yes in uvision the two registers are missing too.

A closer look at the datasheet page 2

"EXTPOLAR and EXTMODE registers are available in /01 parts only."

so if you have the older device the registers are missing.
I guess the alternatine would be to use the input capture and use the captured values to calulate your signal.

Alex

----- Original Message -----
From: warm38spl
To: l...
Sent: Monday, May 23, 2011 6:20 PM
Subject: [lpc2000] Re: speaking of the LPC210x...

I have an older manual. But I have a LPC2106.h file that also omits those. I stole the definitions from a LPC2103.h file, but I could not get the registers to act like they were there. (???)
I just found (I guess I didnt have the search set correctly last time I tried) and downloaded the same User Manual that you have and yup, there they are... now if they would only work.

I set up the External Interrupts like I did with the LPC2138 (the LPC2138 version works just fine). However, with the input signal held at ground, EINT0 stayed in a constant interrupt state and would not let anything else run because it went right back there as soon as it came out. That sure acts like they aren't there, or that the definitions are a lot different than the 2103 or 2138.

From LPC2106.h
#define EXTMODE (*(volatile unsigned char *)0xE01FC148)
#define EXTMODE_EINT0_Lvl 0x00U
#define EXTMODE_EINT0_Edge 0x01U
#define EXTMODE_EINT1_Lvl 0x00U
#define EXTMODE_EINT1_Edge 0x02U
#define EXTMODE_EINT2_Lvl 0x00U
#define EXTMODE_EINT2_Edge 0x04U

#define EXTPOLAR (*(volatile unsigned char *)0xE01FC14C)
#define EXTPOLAR_EINT0_LoFall 0x00U
#define EXTPOLAR_EINT0_HiRise 0x01U
#define EXTPOLAR_EINT1_LoFall 0x00U
#define EXTPOLAR_EINT1_HiRise 0x02U
#define EXTPOLAR_EINT2_LoFall 0x00U
#define EXTPOLAR_EINT2_HiRise 0x04U

From main.c ExtIntInit()
PINSEL0 &= ~(PINSEL0_P0_15MASK); // clear out old functions
PINSEL1 &= ~(PINSEL1_P0_16MASK); // clear out old functions
PINSEL0 |= PINSEL0_P0_15EINT2; // new function
PINSEL1 |= PINSEL1_P0_16EINT0; // new function
EXTMODE = EXTMODE_EINT0_Edge + EXTMODE_EINT2_Edge; // All edge sensitive =0x05
EXTPOLAR = EXTPOLAR_EINT0_HiRise + EXTPOLAR_EINT2_HiRise; // all rising edge =0x05
EXTINT = EXTINT_EINT0 + EXTINT_EINT2; // clear interrupt EINT0+2

My understanding is that EXTMODE defaults are LEVEL and EXTPOLAR is LOW. If I cannot change them then a LOW on EINT0 will cause an interrupt and keep interrupting (which is exactly as I saw). So a HIGH will not allow an interrupt to occur. One thing I did not try (I just now thought of it), was to hold the signal high and verify that the interrupts would not occur. This would give a solid evidence that the registers do not exist (at least on the chip versions on the 3 boards that I have which all act the same).

OK, I'll go back and try a pullup on the pins and see if I get NO interrupts on those pins then put it low and watch for interrupts.

In the event that my chips do not have the EXTMODE/EXTPOLAR registers functional, how would I go about getting the period and duty cycle?

wade

--- In l..., "Alexan_e" wrote:
>
> My user manual has all four registers
>
> LPC2104/2105/2106 User manual
> Rev. 02 - 8 April 2009
>
> Alex
>
> ----- Original Message -----
> From: warm38spl
> To: l...
> Sent: Monday, May 23, 2011 4:53 PM
> Subject: [lpc2000] speaking of the LPC210x...
>
>
>
> I was working on a project with a LPC2106 until I hit a snag.
>
> It seems that the 2101,2102,2103 have a complete External Interrupt setup (like the LPC213x), but the 2106 has a half-baked one. The User Manual on the 2106 does not have the EXTMODE and EXTPOLAR registers. The 2106 only has EXTINT and EXTWAKE.
>
> I was counting on the EXTMODE/EXTPOLAR to be able to detect rising edges so that I can get duty cycle info on an incoming square wave.
>
> Any suggestions on how to capture the duty cycle and period on an incoming square wave without the rising edge external interrupts. The square wave can vary 10-50 Hz and duty cycle 49-51%.
>
> I got spoiled on the 2138.
>
> wade
>
--- In l..., "Alexan_e" wrote:
>
> Yes in uvision the two registers are missing too.
>
> A closer look at the datasheet page 2
>
> "EXTPOLAR and EXTMODE registers are available in /01 parts only."
>
> so if you have the older device the registers are missing.
> I guess the alternative would be to use the input capture and use the captured values to calculate your signal.
>
> Alex

The use of PWM to get the period and duty cycle is something I haven't figured out how to do. Can you point me to some code somewhere on how to set up the PWM to do that?

wade

I don't have any source to provide.

I meant the timer capture, there in no PWM.

Using the CCR register you can set the capture on falling edge or rising edge or both and also if you want an interrupt on capture.

There are four capture registers in each timer, you can set any of them and the associated pins.

The capture register stores the timer value when the capture is triggered, so if you get the timer values for the rising / falling / rising edge you can subtract the values to find what you need.

If you connect two capture pins to the same signal, one for falling edge and one for rising edge then you can get two captures from the rising edges and one from the negatine edge.

The result is in timer ticks so multiply the result with the time of each timer tick (for example a 15MHz timer tick is every 66.67ns)

Download ARMwizard , it will make the timer settings easier http://alexan.edaboard.eu/index.php?page=armwizard

Alex

----- Original Message -----
From: warm38spl
To: l...
Sent: Monday, May 23, 2011 6:57 PM
Subject: [lpc2000] Re: speaking of the LPC210x...

--- In l..., "Alexan_e" wrote:
>
> Yes in uvision the two registers are missing too.
>
> A closer look at the datasheet page 2
>
> "EXTPOLAR and EXTMODE registers are available in /01 parts only."
>
> so if you have the older device the registers are missing.
> I guess the alternative would be to use the input capture and use the captured values to calculate your signal.
>
> Alex

The use of PWM to get the period and duty cycle is something I haven't figured out how to do. Can you point me to some code somewhere on how to set up the PWM to do that?

wade
Hi Wade,

You probably have already noticed, but, just in case you missed it, there's one
potential "gotcha" in the technique Alex described. The technique itself is
fine. Just make sure you watch out for a timer roll-over. Given the small
range of frequencies you're interested in, 10-50 Hz, and the fact that it's a
32-bit timer, you'll easily be able to arrange the timing so you're guaranteed
to get no more than one roll-over in any single rise/fall/rise signal interval.
The roll-over is easy to detect. If an event that is later in time has a
captured timer value that is smaller than a previous value, then, the timer
rolled-over in between the two samples.

Ex:
Sample 1: 0xFFFF FF00
Sample 2: 0xFFFF FFA0
Sample 3: 0x0000 0076

You can see that the timer rolled over between Sample 2 and Sample 3. A
straight subtraction will give a very odd result for the calculated duty cycle
and period.

Unfortunately, I don't have any source I can provide you either. I've never
used the technique on an LPC processor and the hard part is getting the chip set
up correctly to capture the timer values. The math, once you have the capture
values, is trivial.

Cheers,
Norman

________________________________
From: Alexan_e
To: l...
Sent: Mon, May 23, 2011 10:18:32 AM
Subject: Re: [lpc2000] Re: speaking of the LPC210x...

I don't have any source to provide.
I meant the timer capture, there in no PWM.

Using the CCR register you can set the capture on falling edge or rising edge
or both and also if you want an interrupt on capture.
There are four capture registers in each timer, you can set any of them and the
associated pins.

The capture register stores the timer value when the capture is triggered, so
if you get the timer values for the rising / falling / rising edge you can
subtract the values to find what you need.
If you connect two capture pins to the same signal, one for falling edge and
one for rising edge then you can get two captures from the rising edges and one
from the negatine edge.
The result is in timer ticks so multiply the result with the time of each timer
tick (for example a 15MHz timer tick is every 66.67ns)

Download ARMwizard , it will make the timer settings easier
http://alexan.edaboard.eu/index.php?page=armwizard

Alex

----- Original Message -----
>From: warm38spl
>To: l...
>Sent: Monday, May 23, 2011 6:57 PM
>Subject: [lpc2000] Re: speaking of the LPC210x...
>
>
>
>--- In l..., "Alexan_e" wrote:
>>
>> Yes in uvision the two registers are missing too.
>>
>> A closer look at the datasheet page 2
>>
>> "EXTPOLAR and EXTMODE registers are available in /01 parts only."
>>
>> so if you have the older device the registers are missing.
>> I guess the alternative would be to use the input capture and use the
>>captured values to calculate your signal.
>>
>> Alex
>
>The use of PWM to get the period and duty cycle is something I haven't
>figured out how to do. Can you point me to some code somewhere on how to set
>up the PWM to do that?
>wade
Hi,

There is no need to detect rollover in this case. A simple subtraction modulo 2^32 is all that is needed, which the 32-bit “unsigned” type gives you.

0x0000 0076 - 0xFFFF FFA0 = 0xD6.

0xFFFF 00A0 – 0xFFFF FF00 = 0xA0.

This is just moving the number line…

-- Paul.

From: l... [mailto:l...] On Behalf Of Norman Felder
Sent: 23 May 2011 7:06 PM
To: l...
Subject: Re: [lpc2000] Re: speaking of the LPC210x...

Hi Wade,

You probably have already noticed, but, just in case you missed it, there's one potential "gotcha" in the technique Alex described. The technique itself is fine. Just make sure you watch out for a timer roll-over. Given the small range of frequencies you're interested in, 10-50 Hz, and the fact that it's a 32-bit timer, you'll easily be able to arrange the timing so you're guaranteed to get no more than one roll-over in any single rise/fall/rise signal interval. The roll-over is easy to detect. If an event that is later in time has a captured timer value that is smaller than a previous value, then, the timer rolled-over in between the two samples.

Ex:

Sample 1: 0xFFFF FF00

Sample 2: 0xFFFF FFA0

Sample 3: 0x0000 0076

You can see that the timer rolled over between Sample 2 and Sample 3. A straight subtraction will give a very odd result for the calculated duty cycle and period.

Unfortunately, I don't have any source I can provide you either. I've never used the technique on an LPC processor and the hard part is getting the chip set up correctly to capture the timer values. The math, once you have the capture values, is trivial.

Cheers,

Norman

_____

From: Alexan_e
To: l...
Sent: Mon, May 23, 2011 10:18:32 AM
Subject: Re: [lpc2000] Re: speaking of the LPC210x...

I don't have any source to provide.

I meant the timer capture, there in no PWM.

Using the CCR register you can set the capture on falling edge or rising edge or both and also if you want an interrupt on capture.

There are four capture registers in each timer, you can set any of them and the associated pins.

The capture register stores the timer value when the capture is triggered, so if you get the timer values for the rising / falling / rising edge you can subtract the values to find what you need.

If you connect two capture pins to the same signal, one for falling edge and one for rising edge then you can get two captures from the rising edges and one from the negatine edge.

The result is in timer ticks so multiply the result with the time of each timer tick (for example a 15MHz timer tick is every 66.67ns)

Download ARMwizard , it will make the timer settings easier http://alexan.edaboard.eu/index.php?page=armwizard

Alex

----- Original Message -----

From: warm38spl

To: l...

Sent: Monday, May 23, 2011 6:57 PM

Subject: [lpc2000] Re: speaking of the LPC210x...

--- In l..., "Alexan_e" wrote:
>
> Yes in uvision the two registers are missing too.
>
> A closer look at the datasheet page 2
>
> "EXTPOLAR and EXTMODE registers are available in /01 parts only."
>
> so if you have the older device the registers are missing.
> I guess the alternative would be to use the input capture and use the captured values to calculate your signal.
>
> Alex

The use of PWM to get the period and duty cycle is something I haven't figured out how to do. Can you point me to some code somewhere on how to set up the PWM to do that?

wade
Thank you for reminding me of it, however, I have already dealt with it while working with the LPC2138 and LPC2129 timers. The code was available for the 2106 boards, but they couldn't get their sorry selves out of the EINT0 ISR.

I have limited exposure to the Timer Match, but I'm new to the Timer Capture use and I was unaware of the Rising/falling edge. Since I need to know the duty cycle, I will have to manually switch the focus in the ISR between Rising and Falling.

What I was doing before was using an inverter to give myself two rising edges and using two external interrupts to get the time for rising and falling. Now I'm being forced to learn the Capture mode and in the process, drop the need for the inverter.

--- In l..., Norman Felder wrote:
>
> Hi Wade,
>
> You probably have already noticed, but, just in case you missed it, there's one
> potential "gotcha" in the technique Alex described. The technique itself is
> fine. Just make sure you watch out for a timer roll-over. Given the small
> range of frequencies you're interested in, 10-50 Hz, and the fact that it's a
> 32-bit timer, you'll easily be able to arrange the timing so you're guaranteed
> to get no more than one roll-over in any single rise/fall/rise signal interval.
> The roll-over is easy to detect. If an event that is later in time has a
> captured timer value that is smaller than a previous value, then, the timer
> rolled-over in between the two samples.
>
> Ex:
> Sample 1: 0xFFFF FF00
> Sample 2: 0xFFFF FFA0
> Sample 3: 0x0000 0076
>
> You can see that the timer rolled over between Sample 2 and Sample 3. A
> straight subtraction will give a very odd result for the calculated duty cycle
> and period.
>
> Unfortunately, I don't have any source I can provide you either. I've never
> used the technique on an LPC processor and the hard part is getting the chip set
> up correctly to capture the timer values. The math, once you have the capture
> values, is trivial.
>
> Cheers,
> Norman
>

Cool! Thanks Paul,

Norman

________________________________
From: Paul Curtis
To: l...
Sent: Mon, May 23, 2011 12:13:39 PM
Subject: RE: [lpc2000] Re: speaking of the LPC210x...

Hi,

There is no need to detect rollover in this case. A simple subtraction modulo
2^32 is all that is needed, which the 32-bit “unsigned” type gives you.

0x0000 0076 - 0xFFFF FFA0 = 0xD6.
0xFFFF 00A0 – 0xFFFF FF00 = 0xA0.

This is just moving the number line…

-- Paul.

From:l... [mailto:l...] On Behalf Of
Norman Felder
Sent: 23 May 2011 7:06 PM
To: l...
Subject: Re: [lpc2000] Re: speaking of the LPC210x...

Hi Wade,

You probably have already noticed, but, just in case you missed it, there's one
potential "gotcha" in the technique Alex described. The technique itself is
fine. Just make sure you watch out for a timer roll-over. Given the small
range of frequencies you're interested in, 10-50 Hz, and the fact that it's a
32-bit timer, you'll easily be able to arrange the timing so you're guaranteed
to get no more than one roll-over in any single rise/fall/rise signal interval.
The roll-over is easy to detect. If an event that is later in time has a
captured timer value that is smaller than a previous value, then, the timer
rolled-over in between the two samples.

Ex:
Sample 1: 0xFFFF FF00
Sample 2: 0xFFFF FFA0
Sample 3: 0x0000 0076

You can see that the timer rolled over between Sample 2 and Sample 3. A
straight subtraction will give a very odd result for the calculated duty cycle
and period.

Unfortunately, I don't have any source I can provide you either. I've never
used the technique on an LPC processor and the hard part is getting the chip set
up correctly to capture the timer values. The math, once you have the capture
values, is trivial.

Cheers,
Norman

________________________________

From:Alexan_e
To: l...
Sent: Mon, May 23, 2011 10:18:32 AM
Subject: Re: [lpc2000] Re: speaking of the LPC210x...

I don't have any source to provide.
I meant the timer capture, there in no PWM.

Using the CCR register you can set the capture on falling edge or rising edge or
both and also if you want an interrupt on capture.
There are four capture registers in each timer, you can set any of them and the
associated pins.

The capture register stores the timer value when the capture is triggered, so if
you get the timer values for the rising / falling / rising edge you can subtract
the values to find what you need.
If you connect two capture pins to the same signal, one for falling edge and one
for rising edge then you can get two captures from the rising edges and one from
the negatine edge.
The result is in timer ticks so multiply the result with the time of each timer
tick (for example a 15MHz timer tick is every 66.67ns)

Download ARMwizard , it will make the timer settings easier
http://alexan.edaboard.eu/index.php?page=armwizard

Alex

----- Original Message -----
>From:warm38spl
>To:l...
>Sent:Monday, May 23, 2011 6:57 PM
>Subject:[lpc2000] Re: speaking of the LPC210x...
>
>
>
>--- In l..., "Alexan_e" wrote:
>>
>> Yes in uvision the two registers are missing too.
>>
>> A closer look at the datasheet page 2
>>
>> "EXTPOLAR and EXTMODE registers are available in /01 parts only."
>>
>> so if you have the older device the registers are missing.
>> I guess the alternative would be to use the input capture and use the captured
>>values to calculate your signal.
>>
>> Alex
>
>The use of PWM to get the period and duty cycle is something I haven't figured
>out how to do. Can you point me to some code somewhere on how to set up the PWM
>to do that?
>wade