--- In Jim Jackson <> wrote:
>
>
>
>
> On Tue, 23 Jan 2007, chan8337 wrote:
>
> > According to the EP9301 user manual, i have written a sample code to
> > read a voltage level on the GPI0 pin4 which is portC bit0. Once the
> > code is running, i cant get a accurate result. Let say i set the input
> > voltage to 1V but on the terminal the displayed voltage level keep
> > varying.
> >
> > Maybe i missed something that must set in the registers.
> > I have read the sample code provided from Embededarm website. But I
> > cant understand it. It seem like I must correct the ADCResult with the
> > caribration value stored inside the EEPROM.
> >
> > Anyone please help?
>
> In my experience it is often more convenient and easier to use char *
> pointer than int * - obviates the needs to adjust address offsets etc
thanks for your info.
>
> >
> > Just for your info my board is based on the EP9302-CQ cirrus arm
> > processor. Is the register addresses inside the EP9301 user munual
> > valid for EP9302?
> >
> > Below shows the code that i have written.
> > --------------------------------------------------------------------
> > #include<sys/types.h>
> > #include<sys/mman.h>
> > #include<stdio.h>
> > #include<fcntl.h>
> > #include<string.h>
> >
> > main(int argc, char **argv)
> > {
> > volatile unsigned int *SysSWLock, *ADCClkDiv, *DevCfg, *ADCSWLock,
> > *ADCResult, *ADCSwitch, *PBDDR, *PBDR, *GPIOBDB;
> > unsigned char *SysconBase, *ADCBase, *start;
> >
> > float ADResult;
> > unsigned char state;
> >
> > int fd = open("/dev/mem", O_RDWR);
> > SysconBase = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
> > fd, 0x80930000);
> > ADCBase = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd,
> > 0x80900000);
> > start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd,
> > 0x80840000);
> >
> > /*Assign register addresses to pointers according to ep9301 user
guide*/
> > SysSWLock = (unsigned int *)(SysconBase + 0xC0);
> > ADCClkDiv = (unsigned int *)(SysconBase + 0x90);
> > DevCfg = (unsigned int *)(SysconBase + 0x80);
> > ADCSWLock = (unsigned int *)(ADCBase + 0x20);
> > ADCResult = (unsigned int *)(ADCBase + 0x08);
> > ADCSwitch = (unsigned int *)(ADCBase + 0x18);
> >
> > PBDDR = (unsigned int *)(start + 0x14); //port b direction
> > PBDR = (unsigned int *)(start + 0x04); //port b
> > GPIOBDB = (unsigned int *)(start + 0xC4); // debounce on port b
> >
> > /*Setup the PortB to received digital input*/
> > *PBDDR = 0xf0; //upper nibble output, lower nibble input
> > *GPIOBDB = 0x01; //enable debounce on bit 0
> >
> > /*Steps to setup the onboard ADC for ts-7200*/
> > *SysSWLock = 0xAA; //unlock the software lock for the all registers
> > *ADCClkDiv |= 0x80010000; //enable TSEN(bit32)-AD clock start, enable
> > ADIV(bit16)-AD clk/4
> >
> > *SysSWLock = 0xAA; //unlock the software lock for the all registers
> > (AGAIN)
> > *DevCfg |= 0x00020000; //Set the ADCEN - ADC enable.
> >
> > *SysSWLock = 0xAA; //unlock the software lock for the all registers
> > (AGAIN)
> > *DevCfg &= 0xFFFFFFFB; //Clear the ADCPD-ADC. Set 1 to Power Down
> >
> > *ADCSWLock = 0xAA; //unlock the software lock for the all registers
> > (AGAIN)
> > *ADCSwitch = 0x00000608; //Enable AD channel 4 to receive analog
signal.
> >
> > /*do while loop is terminated when portb bit0 is "0". Default pull up
> > to logic "1"*/
> > do
> > {
> > state = *PBDR;
> > while((*ADCResult & 0x80000000)==0x80000000); //pooling until
> > bit31 set then exit.
> > ADResult = ((float)(*ADCResult & 0x00000FFF)/4095)*3;
> > printf("Channel 0 Result: %f \n", ADResult);
> >
> > }while(state & 0x01);
> >
> > close(fd);
> > return 0;
> >
> > }
> >
> >
> >
>
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|