Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[moved] How to ADC and DAC of PCF8591 together

Status
Not open for further replies.

samic45mit1

Member level 3
Joined
Dec 11, 2009
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
indore
Activity points
1,792
Hello,



I try to interface PCF8591 with ATMEGA32. And successfully run DAC and all modes of ADC but when I try to read ADC data and write same data on DAC then this not work. Even when control register of PCF 8591 is reinitialized . First I use internal oscillator of PCF8591 by grounding EXT pin, with this ADC and DAC work correctly (but not together as I mansion). Then I connect EXT pin with VCC and give 75KHz clock form PWM channel of AVR, in this case both ADC and DAC stop working. While using internal oscillator I see that during ADC read operation DAC stop working. Sohow to use ADC and DAC of PCF8591 together(it is possible ??).
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
20,766
Helped
4,484
Reputation
8,980
Reaction score
4,546
Trophy points
1,393
Activity points
137,113
Hi,

I assume it is a software problem...

But to find the problem we need the schematic and the code...

Klaus
 

samic45mit1

Member level 3
Joined
Dec 11, 2009
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
indore
Activity points
1,792
P.jpg

Please see the attachment for schematic and my program is given below.

/*
* PCF8591_ADC.c
*
* Created: 10/19/2015 11:09:52 PM
* Author:
*/


#include "define.h"
#include "twio.c"



const unsigned char start[]PROGMEM="Start";
const unsigned char A0_dis[]PROGMEM="A0=";
const unsigned char A1_dis[]PROGMEM="A1=";
const unsigned char A2_dis[]PROGMEM="A2=";
const unsigned char A3_dis[]PROGMEM="A3=";

void adc_out(unsigned char *AN0,unsigned char *AN1,unsigned char *AN2,unsigned char *AN3);
void init_adc_3diff(unsigned char *AN0,unsigned char *AN1,unsigned char *AN2,unsigned char *AN3);
unsigned char single_read(unsigned char ch);
void dac(unsigned char out);
void init_PCF8591(void);
void pwm_init(void);

int main(void)
{
unsigned char AN0=0,AN1=0,AN2=0,AN3=0;

PORTB=0XFF;
DDRB=0XFF;

PORTA=0XFF;
DDRA=0XFF;

LCDinit(); ms(5);
LCDclr(); ms(5);
LCDGotoXY(0,0); ms(5);

// pwm_init();
init_PCF8591(); //Initialized PCF8591 in DAC mode

while(1)
{
//AN0=single_read(0x00);
LCDGotoXY(0,0);
CopyStringtoLCD(A0_dis,0,0);
dtostrf(AN0,0,0,tem1);
LCDGotoXY(3,0); ms(5);
sendstring(tem1);
sendstring(" ");

ms(10);

//AN1=single_read(0X01);
LCDGotoXY(8,0);
CopyStringtoLCD(A1_dis,8,0);
dtostrf(AN1,0,0,tem1);
LCDGotoXY(11,0); ms(5);
sendstring(tem1);
sendstring(" ");

ms(10);

//AN2=single_read(0X02);
LCDGotoXY(0,1);
CopyStringtoLCD(A2_dis,0,1);
dtostrf(AN2,0,0,tem2);
LCDGotoXY(3,1); ms(5);
sendstring(tem2);
sendstring(" ");

ms(10);

//AN3=single_read(0X03);
LCDGotoXY(8,1);
CopyStringtoLCD(A3_dis,8,1);
dtostrf(AN3,0,0,tem2);
LCDGotoXY(11,1); ms(5);
sendstring(tem2);
sendstring(" ");

adc_out(&AN0,&AN1,&AN2,&AN3);
dac(AN0);

ms(20);
}
}



void init_PCF8591(void)
{
twi_init();
twi_start();
twi_write(0X90); //Send the address of PCF8591
twi_write(0X44); //Set register pointer to 7th register
twi_stop();
return;
}



void adc_out(unsigned char *AN0,unsigned char *AN1,unsigned char *AN2,unsigned char *AN3)
{
twi_start();
twi_write(0X90); //Send the address of DS10307
twi_write(0X05); // 101 (0X05) send to give start channel with auto increment of channel
twi_stop();


twi_start(); ms(10);
twi_write(0X91);

*AN0 = twi_read(0X01); ms(10);
*AN1 = twi_read(0X01); ms(10);
*AN2= twi_read(0x01); ms(10);
*AN3= twi_read(0x00); ms(10);

twi_stop();

ms(2);

return;
}


unsigned char single_read(unsigned char ch)
{
auto unsigned char an0=0;
twi_start();
twi_write(0X90);
twi_write(ch+0x01); //Channel count must start form 1
twi_stop();

ms(10);

twi_start();
twi_write(0X91);
an0=twi_read(0x00);
twi_stop();

return(an0);
}


void init_adc_3diff(unsigned char *AN0,unsigned char *AN1,unsigned char *AN2,unsigned char *AN3)
{
twi_start();
twi_write(0X90); //Send the address of DS10307
twi_write(0X15); // 101 (0X05) send to give start channel with auto increment of channel,three differential input confi
twi_stop();

ms(10)

twi_start(); ms(10);
twi_write(0X91);

*AN0 = twi_read(0X01); ms(10);
*AN1 = twi_read(0X01); ms(10);
*AN2= twi_read(0x00); ms(10);
// *AN3= twi_read(0x00); ms(10); //Channel AN3 is negative refrence so no need to read it

twi_stop();

return;
}


/*void dac(unsigned char out)
{
twi_start();
twi_write(0X90); //Send the address of DS10307
twi_write(0X40); //Set register pointer to 7th register
twi_stop();

twi_write(0X91);
twi_write(out); //Set the register value to 0
twi_stop();
}*/


void dac(unsigned char out)
{
twi_start();
twi_write(0X90); //Send the address of DS10307
twi_write(0X40); //Set register pointer to 7th register
twi_stop();

//twi_start();
twi_write(0X91);
twi_write(out); //Set the register value to 0
twi_stop();
return;
}

/*void pwm_init(void) //Function for 75Khz PWM
{
PORTD=(1<<5);
DDRD=(1<<5);

ICR1H=0X00;
ICR1L=0X90;

OCR1AH=0X00;
OCR1AL=0X19;
TCCR1A=0X82;
TCCR1B=0X19;

return;
}*/
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top