================= main.c
#include <stdlib.h>
#include <stdio.h>
#include "analog_in.h"
void
main(void)
{
int
loop;
InitAnalogIn();
for(loop=0;loop<8;loop++)
printf("Chanel %d: %d\n",loop,ReadAnalogIn(loop,ANALOG_IN_UNIPOLAR|ANALOG_IN_5VOLT);
CloseAnalogIn();
}
============ analog_in.h
#ifndef ANALOG_IN #define ANALOG_IN
#define ANALOG_IN_UNIPOLAR 0 #define ANALOG_IN_BIPOLAR
8 #define ANALOG_IN_5VOLT 0 #define
ANALOG_IN_10VOLT 16
int InitAnalogIn(void); void CloseAnalogIn(void); unsigned short
ReadAnalogIn(int channel,unsigned char control);
#endif
============analog_in.c
#include
"peekpoke.h" #include<unistd.h> #include<sys/types.h> #include<sys/mman.h> #include<stdio.h> #include<fcntl.h> #include<assert.h> #include
"analog_in.h"
volatile unsigned short *
AnalogInComplete=NULL; volatile unsigned char * AnalogInLsb=NULL; volatile
unsigned char * AnalogInMsb=NULL; volatile unsigned char *
AnalogInControl=NULL; int AnalogInHandle=-1;
int
InitAnalogIn(void) {
AnalogInHandle =
open("/dev/mem",O_RDWR); if(AnalogInHandle<0)
return(0);
AnalogInLsb=AnalogInControl= (unsigned char *)
mmap(0,getpagesize(),PROT_WRITE|PROT_READ,MAP_SHARED,AnalogInHandle,0x10c00000); if(AnalogInLsb
==
NULL) { CloseAnalogIn(); return(0); } AnalogInMsb=
AnalogInLsb+1;
AnalogInComplete = (unsigned
short *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED,
AnalogInHandle, 0x10800000); if(AnalogInComplete ==
NULL) { CloseAnalogIn(); return(0); } return(1); }
void
CloseAnalogIn(void) { if(AnalogInLsb)
{ munmap((void
*)AnalogInLsb,getpagesize());
AnalogInLsb=NULL; AnalogInControl=NULL;
} if(AnalogInComplete) {
munmap((void *)AnalogInComplete,getpagesize());
AnalogInComplete=NULL;
} if(AnalogInHandle>=0) { close(AnalogInHandle); } }
unsigned short ReadAnalogIn(int
channel,unsigned char control) {
unsigned short
res=0; control&=0x18; control|=0x40; control|=
(channel & 0x7); // set channel
*AnalogInControl=
control; // start conversion
while((*AnalogInComplete &
0x80) !=0); // wait for completion
res =
*AnalogInLsb; res |= *AnalogInMsb <<
8; return(res); }
This should Help!
Daniel
Hello Jim,
It was not directly the answer that I expected for my
question. I have studied the schematics of the TS-7200 as well the MAX 192
datasheet, from there it should be possibly to understand how the optional
mounted MAX192 would work. The datasheet describes that the HBEN is used
to select bits 8 to 11, however when this is not wired in the schematics,
it this wired on the board or is there any extention to the chip and
datasheet used?
Then I might comment your answer. I have checked
the ts website, www.embeddedarm.com, and they have demo code for the
internal adc. If you are aware of the TS code for Optional mounted MAX
197, I would to be pleased for that link or information. What I found on
TS page is: EP9301 on-board A/D converter sample code <http://www.embeddedarm.com/downloads/samplecode/adc_72xx.tar.gz>
(04-17-2006) however that does not help me in the end to get all 12
bits of the external ADC.
And yes, I have read your code on your
page. You maybe can explain how you get the complete 12 bits from the
optional max197 with just one read, when the chip has only 8 bits ports
with no HBEN. It the Cirrus EP93xx doing some stuff in between or anything
that I missunderstood? You say in your code, adc_read that the value is:
sv=*adc_io_read; where the address point at adc_io_read=(unsigned
short *)IOMMAP(0x10c00000). However reading this once would give the
8 bit of max197? The difference is that the internal ADC is possible to
have all 12 bits read when it is interfaced.
So question remains,
what is done with HBEN on the external mouted MAX197, to get all 12
bits?
/PO
Jim Jackson wrote:
>On Tue, 31 Oct 2006,
Per-Olof wrote: > >
> >>Hello, >> >>I have concerns how to use
all the 12 bits on the MAX197 ADC on TS-7200. >>According to the
schematics the HBEN is not connected to any port or >>function, and
terefore it would not be possible to select to bit 8..11 >>form the
conversion. Either I can't find any register or writing to >>MAX197
that would enable the uppber bits. >>Is it possible to use all 12
bits, or is the board just printed for 8 >>bit (and 8
channel)? >> >> > >I thought Technologics had
put out some demo code for accessing the >MAX197 on a ts7200???? Have
you checked all the docs? > >As I've recently said on another
thread on the MAX197 - you can check >out my adc_logger and adio
software referenced from my ts7200
webpage. > >Jim > >---------------------------------------------------------- >HomePage:
http://www.comp.leeds.ac.uk/jj >TS7200
Page: http://www.comp.leeds.ac.uk/jj/linux/arm-sbc.html >
>
__._,_.___
SPONSORED LINKS
__,_._,___
|