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.

Interfacing ADS8513 ADC with PIC18F45k20

jmahatodeep

Newbie
Joined
Jul 21, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
I'm trying to interface ADS8513 with PIC18F45k20. I'm unable to read data from ADC. I'm using MikroC. I'm also using MCP4921 DAC.
 

jmahatodeep

Newbie
Joined
Jul 21, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
Here is my schematic. I'm trying to generate a time-varying signal using MCP4921 DAC and to read the data using ADS8513 ADC.
 

Attachments

  • Schematic_ADC_DAC.png
    Schematic_ADC_DAC.png
    30.2 KB · Views: 28

Aussie Susan

Advanced Member level 4
Joined
Jan 5, 2015
Messages
1,281
Helped
382
Reputation
764
Reaction score
383
Trophy points
83
Activity points
13,848
Just looking at your schematic, it would appear that you are using SPI to interface with the ADS8513. In that case I strongly suggest that you NEVER tie \CS\ low - you are asking for trouble with the SPI exchanges.
You share the SCK signal from the MCU to both of your SPI peripherals (which is OK in itself) BUT because the \CS\ on the ADS8513 is tied low, it will respond to any values that you try to send tp the MCP4921.
However, you also have the EXT\INT\ pin held low which means the ADS8513 is going to try to generate the clock signal. As \CS\ is tied low, the EXT\INT\ pin will not tri-state and so will also be generating a high or low signal that will conflict with the MCU's SCK signal.
There are simpler ADCs that you can interface with as I get the feeling you are beginning to learn about these things.
Susan
 

jmahatodeep

Newbie
Joined
Jul 21, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
Hi, Susan.
yes, I'm new to this.
I'm attaching the schematic where I've only used ads8513 with an lcd. There also I'm not able to get fruitful results.
Here is my mikroc program:
Code:
sbit Conversion_Select at RC1_bit;
sbit Conversion_Select_Direction at TRISC1_bit;
sbit Slave_Select at RA5_bit;
sbit Slave_Select_Direction at TRISA5_bit;

// LCD module connections (pinout settings)
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

// LCD pin direction
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;

void Init_Main()
{
    Slave_Select=1;
    Slave_Select_Direction=1;
    Conversion_Select=0;
    Conversion_Select_Direction=0;
    SPI1_Init_Advanced(_SPI_SLAVE_SS_ENABLE,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_HIGH_2_LOW);
}
unsigned char SPI_Read1()
{
    SSPBUF=0xff;        /* Copy flush data in SSBUF */
    while(!PIR1.SSPIF);    /* Wait for complete 1 byte transmission */
    PIR1.SSPIF=0;        /* Clear SSPIF flag */
    return(SSPBUF);        /* Return received data.*/
}
short ADC_Value ()
{
    short take, buffer;
    Conversion_Select=1;
    Delay_us(10);
    Conversion_Select=0;
    take=SPI_Read1();
    buffer= (take) & 0x0000;
    buffer= (buffer << 8);
    take=SPI_Read1();
    buffer = (buffer) & (take);
    return (buffer);
}

void main()
{
    char txt[16];
    short i;
    ANSEL  = 0;                           
    ANSELH = 0;
    Init_Main();
    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);                   
    Lcd_Cmd(_LCD_CURSOR_OFF);             

    while(1)
    {
     i = ADC_Value();
     ShortToStr(i,txt);
     Lcd_Out(1,5,"ADC test");
     Lcd_Out(2,1,txt);
    }
}
 

Attachments

  • ads8513_pic18f45k20.png
    ads8513_pic18f45k20.png
    30.4 KB · Views: 13
Last edited by a moderator:

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,443
Helped
292
Reputation
584
Reaction score
277
Trophy points
1,363
Location
France 01800
Activity points
10,149
hello,

Code:
take=SPI_Read1();
    buffer= (take) & 0x0000;     --> gives 0 !
    buffer= (buffer << 8);
    take=SPI_Read1();
    buffer = (buffer) & (take);
    return (buffer);

maybe like this ?


Code:
    take=SPI_Read1();
    buffer= (take<< 8);
    take=SPI_Read1();
    buffer = buffer + (take& 0x00FF) ;
    return (buffer);
 

jmahatodeep

Newbie
Joined
Jul 21, 2021
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
24
hello,

Code:
take=SPI_Read1();
    buffer= (take) & 0x0000;     --> gives 0 !
    buffer= (buffer << 8);
    take=SPI_Read1();
    buffer = (buffer) & (take);
    return (buffer);

maybe like this ?


Code:
    take=SPI_Read1();
    buffer= (take<< 8);
    take=SPI_Read1();
    buffer = buffer + (take& 0x00FF) ;
    return (buffer);
Still, the data transferred to MCU by the ADC is not displayed on LCD.
actually, I am trying to read 16bit data from ADC.
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,443
Helped
292
Reputation
584
Reaction score
277
Trophy points
1,363
Location
France 01800
Activity points
10,149
hello,

for 16 bits use unsigned int, instead of short

Conversions Libraries :
void ShortToStr(short input, char *output);
Converts input short (signed byte) number to a string

void WordToStr(unsigned input, char *output);
Converts input word to a string.
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top