Discussion group dedicated to the Philips LPC2000 family of ARM MCUs
Reading SoftPot with AD - Kevin Townsend - Sep 17 10:57:36 2008
Greetings. I was trying to get a reading from a SoftPot using AD0.1=20
on an Olimex P2148 development board, but I seem to get 0 whatever=20
the value should be.
The datasheet for the SoftPot is here, but it is a normal 3-pin=20
design. I have VCC on pin 1, GND on pin 3, and pin 2 is connected to=20
AD0.1 on the 2148 (P0.28).
If someone has a moment, I'm sure there is something relatively=20
simple I'm leaving out or just not understanding, but I don't see it=20
myself. Maybe I'm completely on the wrong track here?
#include
#include
/* ****************************************************************
Interacts with a spectraSymbol Linear Softpot to determine=20
the point that the user has selected
----------------------------------------------------------------
=B5Processor: LPC2148
=20=20=20=20
Pins Used: P0.28 (AD0.1 on the LPC2148)
=20=20=20=20
Created: 17 September 2008
Kevin Townsend
****************************************************************=20=20
*/
void init_AD0();
unsigned short int read_AD0_1();
int main()
{
unsigned short int value;
VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
while (1)
{
value =3D read_AD0_1();
debug_printf("%u", value);
}
}
void init_AD0()
{
PINSEL0 =3D 0x01; // AD0.1=20
AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
AD0CR |=3D 0x01000000; // Start A/D conversion
}
unsigned short int read_AD0_1()
{
unsigned short int val =3D 0;
val =3D AD0DR1; // Read A/D
return val;
}
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )
Re: Reading SoftPot with AD - Kevin Townsend - Sep 17 10:58:32 2008
I forgot to include the datasheet, sorry:
http://www.sparkfun.com/datasheets/Sensors/Flex/SoftPot-Datasheet.pdf
Kevin
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )
Re: Reading SoftPot with AD - rtstofer - Sep 17 12:16:33 2008
--- In l...@yahoogroups.com, "Kevin Townsend"
wrote:
>
> Greetings. I was trying to get a reading from a SoftPot using AD0.1=20
> on an Olimex P2148 development board, but I seem to get 0 whatever=20
> the value should be.
>=20
> The datasheet for the SoftPot is here, but it is a normal 3-pin=20
> design. I have VCC on pin 1, GND on pin 3, and pin 2 is connected to=20
> AD0.1 on the 2148 (P0.28).
>=20
> If someone has a moment, I'm sure there is something relatively=20
> simple I'm leaving out or just not understanding, but I don't see it=20
> myself. Maybe I'm completely on the wrong track here?
>=20
> #include
> #include
>=20
> /* ****************************************************************
> Interacts with a spectraSymbol Linear Softpot to determine=20
> the point that the user has selected
> ----------------------------------------------------------------
> =B5Processor: LPC2148
>=20=20=20=20=20
> Pins Used: P0.28 (AD0.1 on the LPC2148)
>=20=20=20=20=20
> Created: 17 September 2008
> Kevin Townsend
> ****************************************************************=20=20
> */
>=20
> void init_AD0();
> unsigned short int read_AD0_1();
>=20
> int main()
> {
> unsigned short int value;
>=20
> VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
>=20
> while (1)
> {
> value =3D read_AD0_1();
> debug_printf("%u", value);
> }
> }
>=20
> void init_AD0()
> {
> PINSEL0 =3D 0x01; // AD0.1=20
> AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
> AD0CR |=3D 0x01000000; // Start A/D conversion
> }
>=20
> unsigned short int read_AD0_1()
> {
> unsigned short int val =3D 0;
>=20
> val =3D AD0DR1; // Read A/D
>=20
> return val;
> }
>
At a minimum, you haven't dealt with PCONP to power up the A/D
converter. When you read the value, you are supposed to wait for the
A/D to be ready. And you have to explicitly start each conversion.
Why don't you try the code from www.jcwren.com/arm You will need to
change the port used in the code or the pin used by your hardware. I
suggest rewiring and leaving the code alone.
Richard
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Reading SoftPot with AD - rtstofer - Sep 17 12:32:46 2008
--- In l...@yahoogroups.com, "rtstofer"
wrote:
>
> --- In l...@yahoogroups.com, "Kevin Townsend" wrote:
> >
> > Greetings. I was trying to get a reading from a SoftPot using AD0.1=20
> > on an Olimex P2148 development board, but I seem to get 0 whatever=20
> > the value should be.
> >=20
> > The datasheet for the SoftPot is here, but it is a normal 3-pin=20
> > design. I have VCC on pin 1, GND on pin 3, and pin 2 is connected to=20
> > AD0.1 on the 2148 (P0.28).
> >=20
> > If someone has a moment, I'm sure there is something relatively=20
> > simple I'm leaving out or just not understanding, but I don't see it=20
> > myself. Maybe I'm completely on the wrong track here?
> >=20
> > #include
> > #include
> >=20
> > /* ****************************************************************
> > Interacts with a spectraSymbol Linear Softpot to determine=20
> > the point that the user has selected
> > ----------------------------------------------------------------
> > =B5Processor: LPC2148
> >=20=20=20=20=20
> > Pins Used: P0.28 (AD0.1 on the LPC2148)
> >=20=20=20=20=20
> > Created: 17 September 2008
> > Kevin Townsend
> > **************************************************************** =
=20
> > */
> >=20
> > void init_AD0();
> > unsigned short int read_AD0_1();
> >=20
> > int main()
> > {
> > unsigned short int value;
> >=20
> > VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
> >=20
> > while (1)
> > {
> > value =3D read_AD0_1();
> > debug_printf("%u", value);
> > }
> > }
> >=20
> > void init_AD0()
> > {
> > PINSEL0 =3D 0x01; // AD0.1=20
> > AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
> > AD0CR |=3D 0x01000000; // Start A/D conversion
> > }
> >=20
> > unsigned short int read_AD0_1()
> > {
> > unsigned short int val =3D 0;
> >=20
> > val =3D AD0DR1; // Read A/D
> >=20
> > return val;
> > }
> >
>=20
> At a minimum, you haven't dealt with PCONP to power up the A/D
> converter. When you read the value, you are supposed to wait for the
> A/D to be ready. And you have to explicitly start each conversion.
>=20
> Why don't you try the code from www.jcwren.com/arm You will need to
> change the port used in the code or the pin used by your hardware. I
> suggest rewiring and leaving the code alone.
>=20
> Richard
>
While I'm thinking about it, put a 330 ohm resistor between the output
of the sensor and the A/D input on the uC. Given that you aren't
properly initializing things, it is possible to apply either +5 or Gnd
from the sensor (at the extremes of the device output) to a pin that
isn't set to accept it.
The resistor won't affect the reading (much) but it will save a chip
from errant programming.
It's a good idea to protect every pin with this scheme until the
program is known to work.
Richard
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Reading SoftPot with AD - Kevin Townsend - Sep 17 18:29:23 2008
Richard:
Thanks for the link to the demo code. It's a great resource to pick=20
apart and see how things work on the 214x. Having looked at the ADC=20
example of the site, I made the following changes (below), but still=20
seem to get 0 back.=20=20
The difficulty with taking the code directly from the code you=20
suggested is that there are a handful of other frameworks=20
intertwined, and it's quite complicated to extract just the piece(s)=20
you want, though I did spend a few hours trying.
If anyone has a second and spots something that clearly is off in the=20
code below, I'd appreciate the comments. If not, I'll just have to=20
scratch my head until something clicks.
In any case, thanks for the help provided so far ...
#include
#include
/* ****************************************************************
Interacts with a spectraSymbol Linear Softpot to determine=20
the point that the user has selected
----------------------------------------------------------------
=B5Processor: LPC2148
=20=20=20=20
Pins Used: P0.28 (AD0.1 on the LPC2148)
=20=20=20=20
Created: 17 September 2008
Kevin Townsend
****************************************************************=20=20
*/
void init_AD0();
unsigned short int read_AD0_1();
int main()
{
unsigned short int value;
VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
init_AD0();
while (1)
{
value =3D read_AD0_1();
debug_printf("%u", value);
}
}
void init_AD0()
{
PCONP =3D 0x00001000;
AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
AD0CR |=3D 0x01000000; // Start A/D conversion
PINSEL0 =3D 0x01000000; // AD0.1
}
unsigned short int read_AD0_1()
{
unsigned short int val =3D 0;
// Wait for read to complete
while (!(AD0DR1 & 0x80000000))
;
// Return results
return ((AD0DR1 & 0x0000ffc0) >> 6);
}
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Reading SoftPot with AD - rtstofer - Sep 17 20:34:23 2008
--- In l...@yahoogroups.com, "Kevin Townsend"
wrote:
>
> Richard:
>=20
> Thanks for the link to the demo code. It's a great resource to pick=20
> apart and see how things work on the 214x. Having looked at the ADC=20
> example of the site, I made the following changes (below), but still=20
> seem to get 0 back.=20=20
>=20
> The difficulty with taking the code directly from the code you=20
> suggested is that there are a handful of other frameworks=20
> intertwined, and it's quite complicated to extract just the piece(s)=20
> you want, though I did spend a few hours trying.
>=20
> If anyone has a second and spots something that clearly is off in the=20
> code below, I'd appreciate the comments. If not, I'll just have to=20
> scratch my head until something clicks.
>=20
> In any case, thanks for the help provided so far ...
>=20
> #include
> #include
>=20
> /* ****************************************************************
> Interacts with a spectraSymbol Linear Softpot to determine=20
> the point that the user has selected
> ----------------------------------------------------------------
> =B5Processor: LPC2148
>=20=20=20=20=20
> Pins Used: P0.28 (AD0.1 on the LPC2148)
>=20=20=20=20=20
> Created: 17 September 2008
> Kevin Townsend
> ****************************************************************=20=20
> */
>=20
> void init_AD0();
> unsigned short int read_AD0_1();
>=20
> int main()
> {
> unsigned short int value;
>=20
> VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
>=20
> init_AD0();
>=20
> while (1)
> {
> value =3D read_AD0_1();
> debug_printf("%u", value);
> }
> }
>=20
> void init_AD0()
> {
> PCONP =3D 0x00001000;
> AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
> AD0CR |=3D 0x01000000; // Start A/D conversion
>=20
> PINSEL0 =3D 0x01000000; // AD0.1
> }
>=20
> unsigned short int read_AD0_1()
> {
> unsigned short int val =3D 0;
>=20
> // Wait for read to complete
> while (!(AD0DR1 & 0x80000000))
> ;
>=20
> // Return results
> return ((AD0DR1 & 0x0000ffc0) >> 6);
> }
>
I think you want to use PINSEL1 =3D 0x01000000 Your first AD0CR should
probably be something else (but I'm not going to try to decode it) and
the second should be omitted (start).
In your read loop put before the while loop:
AD0_CR =3D 0x01000000; // start conversion
In the demo file lpc2106.h there are definitions for all the symbolic
constants used in the demo code. You should probably include it in
your code rather than using numeric constants.
If you do this you can use the demo code exactly as given changing
only AD_CR_SEL3 to AD_CR_SEL1.
There's really nothing twisted about the demo A/D code. Just omit the
FreeRTOS stuff and include lpc2106.h. In fact, change your hardware
to use AD0.3 so you don't have to change a single line of code.
Richard
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )Re: Re: Reading SoftPot with AD - Dave Such - Sep 18 10:52:17 2008
I use this function with a LPC2292 without problems
#define AIN0 0x00400000 // AIN0 (23:22)
PINSEL1 =3D AIN0;
//----------------------
> =B5Processor: LPC2148
>
> Pins Used: P0.28 (AD0.1 on the LPC2148)
>
> Created: 17 September 2008
> Kevin Townsend
> ****************************************************************
> */
>
> void init_AD0();
> unsigned short int read_AD0_1();
>
> int main()
> {
> unsigned short int value;
>
> VPBDIV =3D 0x02; // Set the PCLK to 30 MHz
>
> init_AD0();
>
> while (1)
> {
> value =3D read_AD0_1();
> debug_printf("%u", value);
> }
> }
>
> void init_AD0()
> {
> PCONP =3D 0x00001000;
> AD0CR =3D 0x00270601; // 10-bit AIN0 at 3 MHz
> AD0CR |=3D 0x01000000; // Start A/D conversion
>
> PINSEL0 =3D 0x01000000; // AD0.1
> }
>
> unsigned short int read_AD0_1()
> {
> unsigned short int val =3D 0;
>
> // Wait for read to complete
> while (!(AD0DR1 & 0x80000000))
> ;
>
> // Return results
> return ((AD0DR1 & 0x0000ffc0) >> 6);
> }
>
>=20=20
[Non-text portions of this message have been removed]
------------------------------------

(You need to be a member of lpc2000 -- send a blank email to lpc2000-subscribe@yahoogroups.com )