EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Analog Inputs on LPC2103 with 16x4 LCD Module

Started by soufeazie October 11, 2006
Hello, I am relatively new to microcontroller programming and have
been banging my head against the wall for the past couple of weeks
trying to configure my lpc2103 controller to function properly. I
have got an hd44780 based LCD module and have successfully configured
it to display text...that was good. Now, I am currently spinning my
wheels trying to read an analog input port. I have looked through the
user's manual for my microcontroller as well as the LPC-ARM book
published on the web. I have still not been able to correctly sample
and display an analog input. I believe the problem stems from the R/W
register of the LCD "taking over" pin P0.22, which I believe is the
pin for analog input 1. I have included links to the owner's manual
for the microcontroller and LCD I'm working with (pin block diagram
describes the functionality of each pin) and have also included the
main body of the code I have so far...which doesn't work! I would
really appreciate any information on configuring and using the analog
input ports 2,3,4,5,6,7 (these do not interfere with the LCD pins).
Thanks in advance for your help!

-David

http://www.standardics.nxp.com/support/documents/microcontrollers/pdf/user.manual.lpc2101.lpc2102.lpc2103.pdf

http://www.futurlec.com/LED/LCD16X4BL.shtml

An Engineer's Guide to the LPC2100 Series

While you code kinda looks OK, it would be more readable to set the
control register to the value you want in 1 or 2 steps, and faster too.

One other issue that may be causing a problem, is that if the analog
mux is being used then no analog input may exceed 3.3V. This is from
the errata on the 2103, I haven't tested this and don't know if it
means even when that analog input is used as a digital line.

Anyway here is the code we use to read an A/D



Bruce
www.coridiumcorp.com
home of the ARMexpress modules and ARMmite SBCs
Bruce, thanks for the response! I have tried to adapt your code to
the header file I'm using (lpc2103.h), but have not figured out what
"mb_accum" refers to. The ADC section of the header is shown below.
I have made the following adaptions to the code so far:

PCB_PINSEL0 -> PINSEL0
PCB_PINSEL1 -> PINSEL1
AD_ADGDR -> ADGDR
AD_ADCR -> ADCR
GPIO_IODIR -> IODIR
AD_ADSTAT -> ADSTAT

Is there anything wrong with the header file I'm using? I'm not sure
if the above changes preserve the functionality of your code or
not...there are still errors when I compile, and the errors are shown
below. If you have any idea how to correct this, or what these errors
mean, I would greatly appreciate your help! Thanks again.

MAIN.C(108): error C67: 'FOSC': undefined identifier
MAIN.C(108): error C67: 'PLL_MUL': undefined identifier
MAIN.C(108): error C67: 'PBSD': undefined identifier
MAIN.C(110): error C67: 'mb_accum': undefined identifier
MAIN.C(115): error C67: 'FOSC': undefined identifier
MAIN.C(115): error C67: 'PLL_MUL': undefined identifier
MAIN.C(115): error C67: 'PBSD': undefined identifier
MAIN.C(119): error C67: 'mb_accum': undefined identifier
/* Analog/Digital Converter (ADC) */
#define ADCR (*((volatile unsigned long *) 0xE0034000))
#define ADGDR (*((volatile unsigned long *) 0xE0034004))
#define ADINTEN (*((volatile unsigned long *) 0xE003400C))
#define ADDR0 (*((volatile unsigned long *) 0xE0034010))
#define ADDR1 (*((volatile unsigned long *) 0xE0034014))
#define ADDR2 (*((volatile unsigned long *) 0xE0034018))
#define ADDR3 (*((volatile unsigned long *) 0xE003401C))
#define ADDR4 (*((volatile unsigned long *) 0xE0034020))
#define ADDR5 (*((volatile unsigned long *) 0xE0034024))
#define ADDR6 (*((volatile unsigned long *) 0xE0034028))
#define ADDR7 (*((volatile unsigned long *) 0xE003402C))
#define ADSTAT (*((volatile unsigned long *) 0xE0034030))

-David
Just to let you know what's happening, I have changed the mb_accum in
the if() statements in get_adin() definition to "port". I am reading
an unstable value between 0 and 65472 (continually fluctuates). I had
to comment out the AD_DIV definition to allow the program to compile.

-David
Sorry David-

I was cutting and pasting.

the if(mb_accum) should have been if(port) as you noted.

AP_DIV is 4 in my setup, 60 MHz PCLK, 15 MHz peripheral clock
It may be different in your setup

Bruce
www.coridiumcorp.com
home of ARMexpress modules and ARMmite SBC
--- In l..., "viskr" wrote:
>
> Sorry David-
>
> I was cutting and pasting.
>
> the if(mb_accum) should have been if(port) as you noted.
>
> AP_DIV is 4 in my setup, 60 MHz PCLK, 15 MHz peripheral clock
> It may be different in your setup
>
> Bruce
> www.coridiumcorp.com
> home of ARMexpress modules and ARMmite SBC
>

Thank you VERY much for the help, Bruce. You have no idea how much
trouble you've saved me! I have been playing around with the program
since you initially sent the code, and am able to successfully read
analog inputs 2-7, like I initially wanted. I ended up changing
AP_DIV to 4 also. I will paste the code below just in case it could
be helpful to somebody else who is using my board and LCD combo.
Thanks again for spending some of your time on this issue.

-David


The 2024 Embedded Online Conference