Continue to Site

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.

external ADC (ADS1262) with PIC24F

Letibobo

Newbie
Joined
May 5, 2024
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
29
Hello, need some helps please i have few time (one week) to translate an arduino code in MPLAB. The code allows us to convert analog value voltage to numerical signal. We have done this by use arduino software with arduino due board and now we want to have the fonctionalities in mplab. The problem is that there is not library for ADS1262 in the mplab so we need to code the bits ourselves. Please, there is someone here who can us please ? We are lost, THANK YOU so much in advance.
This is the code:
#include <SPI.h>
#include "ads1262.h" // Include the ADS1262 library header file

#define ADS1262_DRDY_PIN 6
#define ADS1262_CS_PIN 7
#define ADS1262_START_PIN 5
#define ADS1262_PWDN_PIN 4

ads1262 PC_ADS1262;

void setup() {
// Initialize SPI communication
SPI.begin();

// Set ADS1262 control pins as outputs
pinMode(ADS1262_DRDY_PIN, INPUT);
pinMode(ADS1262_CS_PIN, OUTPUT);
pinMode(ADS1262_START_PIN, OUTPUT);
pinMode(ADS1262_PWDN_PIN, OUTPUT);

// Initialize ADS1262
PC_ADS1262.ads1262_Init();

// Reset ADS1262 to ensure a clean start
PC_ADS1262.ads1262_Reset();

// Configure ADS1262 for differential input on AIN9 (channel 9)
PC_ADS1262.ads1262_Reg_Write(0x02, 0x20); // MUX0 register: Configure AINP = AIN9, AINN = AINCOM

// Enable start of conversions
PC_ADS1262.ads1262_Enable_Start();

Serial.begin(9600);
Serial.println("ADS1262 initialized successfully");
}

void loop() {
// Check for data ready (DRDY) signal from ADS1262
if (digitalRead(ADS1262_DRDY_PIN) == LOW) {
// Start reading data from ADS1262
PC_ADS1262.ads1262_Start_Read_Data_Continuous();

// Wait for data conversion to complete
delay(100); // Adjust delay as needed based on ADS1262 output data rate

// Read ADC data from ADS1262
char* data = PC_ADS1262.ads1262_Read_Data();

// Process ADC data (assuming 24-bit data format)
int32_t adcValue = ((int32_t)data[1] << 16) | ((int32_t)data[2] << 8) | (int32_t)data[3];

// Convert ADC data to voltage (assuming 2.5V reference and gain of 1)
float voltage = (adcValue * 2.5) / 8388607.0; // 2^23 - 1 (for 24-bit resolution)

// Read analog input from Arduino Due (A5) and convert to voltage
int analogValue = analogRead(A5);
float analogVoltage = analogValue * (3.3 / 1023.0); // Assuming 3.3V reference on Arduino Due

// Display both voltages on Serial Monitor
Serial.print("Readout voltage from ADS1262 (AIN9): ");
Serial.print(voltage);
Serial.println(" V");

Serial.print("Analog input voltage from Arduino Due (A5): ");
Serial.print(analogVoltage);
Serial.println(" V");

// Stop continuous data read mode
PC_ADS1262.ads1262_Stop_Read_Data_Continuous();
}
}
 
I can think of two ways to approach this from where you are:
1) look at the Arduino library code for the functions that you are calling. The code is easy to find (I found it in about 30 seconds) and write the equivalent for the PIC
2) look at the data sheet for the ADS1262 (learning to read a data sheet is a critical step in your education) and write to the chip via the SPI module in the MCU (that is very straight forward for the SPI module). Section 9.5 of the data sheet tells you all about the commands and the registers (which on a very quick scan seem to be mainly used for the chip setup and then you use the 'start', 'stop' and 'read' commands after that).
Susan
 
Hi,

Yes, reading and understanding the datasheet is important.

Then you need to decide how you want the ADC to operate. (read the datsaheet about opeation modes and filter settings).
And - of course - you need to do the hardware wiring according datasheet and your decisions.

If you expect someone to write code for you: consdier to pay for the work
In either casse you need to set up a detaileld descritpion, flow charts and so on.... (even if you program on your own)

***
The device uses an standardized SPI interface. So the communication is rather easy, no need to bitwise timing.
Just send the commands according the datasheet and process the received data.

Klaus
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top