Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/29/03 10:44
Read: times


 
#53630 - using 2 channels adc
i have written this code for max1118 in keil, but im only using one input channel, what would be a good way to use both channels? channel one is activated by a second pulse on the convst pin. i have got this far in the code but a bit stuck what to do to scan both input channels, code works with one channel, even though the voltage output is slightly wrong, i think its due to the ref/channel ip impedences

ps..have not used for loops because at 1st i couldnt get it to work with for loops so thought it might be the timing out.


code follows:

#include "AdcReg52.h"
#include <intrins.h> //needed for nop

#define channel0 0
#define channel1 1

typedef unsigned char byte;
typedef unsigned int word;

void tst_nop (void);
byte read_max1118(byte channel);
void timer_init(void);
void send_message(byte *send_string);
void delay(word value);
void bintodec(word bth);
byte data serial[13];

void main(void)
{
word data convert;
word data test;
SP=0x7f;
timer_init();
P1 = 0xFC;
CNVST = 1;//channel 0 for testing (P1.2)
CNVST = 0;
SCLK=1;// P1.0 high 1.09uS
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low

while(1)
{
convert = read_max1118(byte channel);
test = (convert*=2);
bintodec(test);
serial[1] = 0x2E;//'.'
serial[4] = 0x20;//' '
serial[5] = 0x56;//'V'
serial[6] = 0x6F;//'o'
serial[7] = 0x6C;//'l'
serial[8] = 0x74;//'t'
serial[9] = 0x73;//'s'
serial[10] = 0x0D;
serial[11] = 0x0A;
serial[12] = 0x00;
send_message(serial);//send result to remote terminal
delay(1000);
}
}



void tst_nop (void)
{
_nop_ (); /* delay for hardware */
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
}



byte read_max1118(void)
{
byte data value;

CNVST = 1;//channel 0 for testing (P1.2)
CNVST = 0;
tst_nop();//wait for conversion 7.5uS

ACC7=DOUT; //1.09uS
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC6=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC5=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC4=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC3=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC2=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC1=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low
ACC0=DOUT;
SCLK=1;// P1.0 high
SCLK=0;// P1.0 low


value = ACC;
return(value);
}

void send_message(byte *send_string)
{
while(*send_string)
{
SBUF = *send_string++;
while(!TI);
TI=0;
}

}

void timer_init(void)
{
PCON &= 0x7F;
SCON = 0x40;//8 bit, 1 start bit, 1 stop bit, variable baud rate (mode1)
TMOD = 0x10; //timer1 - 16bit
TCON = 0x40; //timer1 flag set
RCAP2H = 0xFF;
RCAP2L = 0xDC;
T2CON = 0x14;
TI = 0;
}

void delay(word value) //1ms delay
{
word data i;
for (i=0; i<value;i++)
{
TF1=0;
TR1=0;
TL1=0x18;
TH1=0xFC;
TR1=1;
while(TF1!=1);
TR1=0;
TF1=0;
}
}

void bintodec(word bth)
{
word data hun_dec;
word data ten_dec;
word data unit_dec;

hun_dec = bth; // get 100s digit value
hun_dec /= 100;
hun_dec += 0x30; // convert digit to ASCII
serial[0] = hun_dec; // put into convert buffer

ten_dec = bth % 100; // get remainder from 100s calc
unit_dec = ten_dec % 10; // get remainder from 10s calc
ten_dec /= 10; // get 10s digit value
ten_dec += 0x30; // make 10s into ASCII
serial[2] = ten_dec; // place 10s into convert buffer

unit_dec += 0x30; // convert units into ASCII
serial[3] = unit_dec; // put units into buffer
}




thanks


List of 3 messages in thread
TopicAuthorDate
using 2 channels adc            01/01/70 00:00      
   RE: using 2 channels adc            01/01/70 00:00      
      RE: using 2 channels adc            01/01/70 00:00      

Back to Subject List