DPRG
DPRG List  



[DPRG] reading a Cds via Port E on a HC11 (software)

Subject: [DPRG] reading a Cds via Port E on a HC11 (software)
From: Mike McCarty jmccarty at ssd.usa.alcatel.com
Date: Mon Jun 25 10:52:52 CDT 2001

On Mon, 25 Jun 2001, montgomery f. tidwell wrote:

> Howdy,
> 
> ok, i think i've got the hardware part. now i need some help with
> the software.
> 
> here is the routine that i'm using
> 
> 
> /* the Cds is connected to PORT E pin 0 */
> 
> OPTION |= 0x80;
> ADCTL = 0x10;
> 
> while(1)
> {
>    while((ADCTL&0x80)==0);
>    printf("%d, %d, %d, %d\n",ADR1,ADR2,ADR3,ADR4);
>    ADCTL = 0x10;
> }
> 
> 
> the values that printout do seem to change, but not in response
> to anything that i do to the Cds.
> 
> does this snippet look like it should work?

There are several little "gotchas" when dealing with the A/D.

First, I see that you enable the A/D. But I don't see that you
initialize CSEL. Are you sure your clock is fast enough?

Second, is Vrh - Vrl at least 3 volts?

Third, you don't show what OPTION, ADCTL, ADR1, ADR2, ADR3, and ADR4
are defined to be. Presumably they are

    #define OPTION (*(unsigned char *)0x1039)
    #define ADCTL  (*(unsigned char *)0x1030)
    #define ADR1   (*(unsigned char *)0x1031)
    #define ADR2   (*(unsigned char *)0x1032)
    #define ADR3   (*(unsigned char *)0x1033)
    #define ADR4   (*(unsigned char *)0x1034)

or similar.

Have you tried replacing the photocell with just a variable resistor?

Next, are you sure you have hooked up to the right pin?

You have turned on MULT. No more than one of those values can have any
meaning. You requested it to look at channels 0, 1, 2, and 3. I suspect
you meant to scan one port 4 times. For that you need

    ADCTL = <channel number>;

Mike
-- 
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
I can explain it for you, but I can't understand it for you.
I don't speak for Alcatel      <- They make me say that.



More information about the DPRG mailing list