1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Analog device made ECG circuit and Arduino Uno interface

Discussion in 'Arduino' started by MD MUBDIUL HASAN, Sep 17, 2015.

  1. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Hello,
    From your huge experience can you tell me is it possible to interface EVAL-ADAS1000SDZECG Front-End development board with Arduino Uno?
    I mean I want to control this board by Arduino Uno instead of EVAL-SDP-CB1Z(Analog Devices system demonstration platform).

    What factor should I consider for USB communications to the PC by Arduino Uno? Like ADC,register, SDRAM memory,internal RAM memor?Kindly response me.
     
  2. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Yep but you may want to ask that differently. Like can a arduino read a ekg or ecg
    But I'd use something a little better ARDUINO ZERO $49 bucks
    http://www.amazon.com/Arduino-Zero-Pro-Cortex-M0-SAMD21/dp/B00US73ZIO
    ww.analog.com/media/en/technical-documentation/technical-articles/MS-2160.pdf
    http://www.analog.com/en/products/a.../ad-converters/adas1000.html#product-overview
    http://www.analog.com/en/products/amplifiers/instrumentation-amplifiers/ad8226.html
    http://www.analog.com/en/products/amplifiers/instrumentation-amplifiers/ad8221.html
    http://www.analog.com/en/products/amplifiers/instrumentation-amplifiers/ad8220.html
     
    Last edited: Sep 17, 2015
  3. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Hello Sir,

    Thank you for your response. Its useful indeed.
    You looks very experienced engineer. I have couple of things to know from you.

    I am trying to control few devices together at a time with Arduino Uno. Only with is kit IDE , I need to write code to "read" ECG or other device.
    Few questions came in my mind as follows.

    1. This ECG EVAL-ADAS1000SDZ evaluation board has SPI connector that can be used to extract ECG data from main MCU. Do you think its possible to control whole evaluation board by SPI code?

    2. EVAL-SDP-CB1Z is a Blackfin (ADSP-BF527) based board (You can refer the features of this DSP processor in website, 16/32 processor, 600MHz, 32MB SDRAM etc.). Usually this hardware is used to capture the raw data/ or may be some basic procession on processor itself (not sure what are the algorithm running) and data is send over to PC and other processing is done in LabView software. This ECG EVAL-ADAS1000SDZ is supported by EVAL-SDP-CB1Z(Analog Devices system demonstration platform. Do you think SPI can be received by PC without connecting EVAL-SDP-CB1Z?

    3. Each register size of ADAS1000 is around 32 bit, is it compatible to control by Arduino main MCU Atmega328?

    Hope you will response me.

    Best Regards
    Hasan
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn

    http://www.amazon.com/Arduino-Zero-Pro-Cortex-M0-SAMD21/dp/B00US73ZIO
    You'll need something faster like Arduino-Zero uno to slow.
     
  6. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Dear Sir,

    Do you have sample any ECG SPI code for Arduino?
    Kindly share it.
    Regards
    Hasan
     
  7. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Ardunio uno is too slow from what I have read. Theres a reason they used a blackfin
     
    • Agree Agree x 1
  8. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Dear Sir,

    Arduino Uno has 8-bit buffer. Even my master ADAS1000 has speed data output rates (32 bit), I think it should work. Usually SPI read or write function N number of times to generate SPI clock and read the 32 bit or higher bit data’s (32/N number of times.
    Its SPI protocol is little complected as 4 bytes data has to be read, send, receive at a same time.

    ADAS1000 datasheet gives the SPI configuration in page 50-52. For 2kHz setting there is frame or data packet rate. Dont you think, clock divider datamode ect for Arduino Uno should be added? How about serial braud rate?
    Besides CS pin, if you look in clock at figure 2 there is another pin called DRDY (data ready pin) . The logic is it should be always LOW when CS is HIGH. How to define this function in code? Should we need inturrupt for DRDY pin?

    You can see there is 16 bit or 24 bit data format. According to 28 table the ECGTCL register adress is 0x01 and if you arrange this Enable mode from the bottom of the column like 1000110...... (for example), it make sense. Now question is how to read and write this data? What should be ADAS 1000 read and write command for this register?

    I saw ADAS1000 SPI is done by YRDKRX62N(https://wiki.analog.com/resources/tools-software/uc-drivers/renesas/adas1000) eval board which is more complicated code having different main file and header. They tried to manage all device configuration.


    Here we go ...kindly help me to make correction please,

    Code (c):

    // SPI

    #define DOUT 11 //MOSI

    #define DIN 12 //MISO

    #define SPICK 13 //SCK



    // pins

    #define PIN_CS  7

    #define PIN_DRDY  6



    // the ADAS communicates using SPI, so include the library:

    #include <SPI.h>





    int DRDY = 6;

    int CS = 7;



    union FourByte{

      struct {

      unsigned long value:32; //32bit register values go in here

      byte command:8; //8bit command goes in here.

      };

      byte bit8[4]; //this is just used for efficient conversion of the above into 4 bytes.

    };



    void setup() {

      Serial.begin(115200);



      // start the SPI library:

      SPI.begin();

      SPI.setDataMode(SPI_MODE3);

      SPI.setClockDivider(SPI_CLOCK_DIV16);

      SPI.setBitOrder(MSBFIRST);

      // initalize the  data ready and chip select pins:

      pinMode(DRDY, INPUT);

      pinMode(CS, OUTPUT);

    }

    void loop(){

    unsigned long register = SPI_read(0x01);

    Serial.print("register=");

    Serial.println(register);

    delay(100);

    }

    void SPI_write(union FourByte data) {

    digitalWrite(CS,LOW); //Using CS pin, so sync1/sync0 bytes not needed

    for(char i = 3; i >= 0; i--){

      SPI.transfer(data.bit8[i]); //transfer all 4 bytes of data - command first, then Big Endian transfer of the 32bit value.
    }
    digitalWrite(CS,HIGH);
    }

    unsigned long SPI_read(byte command){
    digitalWrite(CS,LOW); //SS goes low to mark start of transmission
    union FourByte data = {0xF804BE,command}; //generate the data to be sent, i.e. your command plus the Sync bytes.
    for(char i = 3; i >= 0; i--){
      data.bit8[i] = SPI.transfer(data.bit8[i]); //send the data whilst reading in the result
    }
    digitalWrite(CS,HIGH); //SS goes high to mark end of transmission
    return data.value; //return the 32bit value recieved.
    }
     
     
    Last edited by a moderator: Oct 7, 2015
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,164
    Likes:
    910
    Location:
    Rochdale UK
    ONLINE
    Please try to use code tags!!! If you use "i" in an array the normal text editor see's a italic command and screws it all up!!

    The word "CODE=C" in square brackets at the beginning and "/CODE" in square brackets at the end..
     
    • Agree Agree x 1
  10. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Thank you sir. Can you find error elsewhere?
    What to do for read command in this line?
    union FourByte data ={0xF804BE,command};//generate the data to be sent, i.e. your command plus the Sync bytes.
    Here, 0xF804BE should place in Hex form or binary?
    in some Arduino code I saw they place 0b plus binary form of data.
    For example,0b111110000000010010111110.

    Kindly help me.
     
  11. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Have a look at this it will help you understand how to use spi
    I don't think you want to use serial at full speed may cause problems with your buffers.
    If you use SPI.begin() it sets spi to the best setting for you arduino the way you have it dosen't set everything I would use SPI.begin.
    Code (text):
    /*
    SCP1000 Barometric Pressure Sensor Display

    Shows the output of a Barometric Pressure Sensor on a
    Uses the SPI library. For details on the sensor, see:
    http://www.sparkfun.com/commerce/product_info.php?products_id=8161
    http://www.vti.fi/en/support/obsolete_products/pressure_sensors/

    This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
    http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip

    Circuit:
    SCP1000 sensor attached to pins 6, 7, 10 - 13:
    DRDY: pin 6
    CSB: pin 7
    MOSI: pin 11
    MISO: pin 12
    SCK: pin 13

    created 31 July 2010
    modified 14 August 2010
    by Tom Igoe
    */

    // the sensor communicates using SPI, so include the library:
    #include <SPI.h>

    //Sensor's memory register addresses:
    const int PRESSURE =0x1F;     //3 most significant bits of pressure
    const int PRESSURE_LSB =0x20;//16 least significant bits of pressure
    const int TEMPERATURE =0x21;//16 bit temperature reading
    const byte READ =0b11111100;   // SCP1000's read command
    const byte WRITE =0b00000010;// SCP1000's write command

    // pins used for the connection with the sensor
    // the other you need are controlled by the SPI library):
    const int dataReadyPin =6;
    const int chipSelectPin =7;

    voidsetup(){
    Serial.begin(9600);

    // start the SPI library:
      SPI.begin();

    // initalize the  data ready and chip select pins:
    pinMode(dataReadyPin,INPUT);
    pinMode(chipSelectPin,OUTPUT);

    //Configure SCP1000 for low noise configuration:
      writeRegister(0x02,0x2D);
      writeRegister(0x01,0x03);
      writeRegister(0x03,0x02);
    // give the sensor time to set up:
    delay(100);
    }

    voidloop(){
    //Select High Resolution Mode
      writeRegister(0x03,0x0A);

    // don't do anything until the data ready pin is high:
    if(digitalRead(dataReadyPin)==HIGH){
       //Read the temperature data
       int tempData = readRegister(0x21,2);

       // convert the temperature to celsius and display it:
       float realTemp =(float)tempData /20.0;
       Serial.print("Temp[C]=");
       Serial.print(realTemp);


       //Read the pressure data highest 3 bits:
       byte pressure_data_high = readRegister(0x1F,1);
        pressure_data_high &=0b00000111;//you only needs bits 2 to 0

       //Read the pressure data lower 16 bits:
       unsignedint pressure_data_low = readRegister(0x20,2);
       //combine the two parts into one 19-bit number:
       long pressure =((pressure_data_high <<16)| pressure_data_low)/4;

       // display the temperature:
       Serial.println("\tPressure [Pa]="+ String(pressure));
    }
    }

    //Read from or write to register from the SCP1000:
    unsignedint readRegister(byte thisRegister,int bytesToRead){
    byte inByte =0;         // incoming byte from the SPI
    unsignedint result =0;// result to return
    Serial.print(thisRegister,BIN);
    Serial.print("\t");
    // SCP1000 expects the register name in the upper 6 bits
    // of the byte. So shift the bits left by two bits:
      thisRegister = thisRegister <<2;
    // now combine the address and the command into one byte
    byte dataToSend = thisRegister & READ;
    Serial.println(thisRegister,BIN);
    // take the chip select low to select the device:
    digitalWrite(chipSelectPin,LOW);
    // send the device the register you want to read:
      SPI.transfer(dataToSend);
    // send a value of 0 to read the first byte returned:
      result = SPI.transfer(0x00);
    // decrement the number of bytes left to read:
      bytesToRead--;
    // if you still have another byte to read:
    if(bytesToRead >0){
       // shift the first byte left, then get the second byte:
        result = result <<8;
        inByte = SPI.transfer(0x00);
       // combine the byte you just got with the previous one:
        result = result | inByte;
       // decrement the number of bytes left to read:
        bytesToRead--;
    }
    // take the chip select high to de-select:
    digitalWrite(chipSelectPin,HIGH);
    // return the result:
    return(result);
    }


    //Sends a write command to SCP1000

    void writeRegister(byte thisRegister,byte thisValue){

    // SCP1000 expects the register address in the upper 6 bits
    // of the byte. So shift the bits left by two bits:
      thisRegister = thisRegister <<2;
    // now combine the register address and the command into one byte:
    byte dataToSend = thisRegister | WRITE;

    // take the chip select low to select the device:
    digitalWrite(chipSelectPin,LOW);

      SPI.transfer(dataToSend);//Send register location
      SPI.transfer(thisValue);//Send value to record into register

    // take the chip select high to de-select:
    digitalWrite(chipSelectPin,HIGH);
    }
     
     
    Last edited: Oct 8, 2015
  12. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Dear Sir,

    I already work on this code from Arduino library.
    The reason why I use clock divider and datamode is because this ADAS1000 gives clock pulse in form of data for certain frequency range and packet.
    It has to be send and receive 4 bytes data at a time.


    My difficulties are configuring all register and handle many operations.
    One reference could give an idea,
    http://www.mit.edu/~gari/CODE/ECG_lab/ecg_ads1292.ino

    Best Regards
    Hasan
     
  13. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    If you read the spi the arduino can only send 2 bytes at a time and the link you showed is for a
    Teensy that's a arm 32 bit uc and a lot faster then the atmega and the setting are for it not a arduino.
    all the arduino needs is
    Code (text):
    SPI.begin()
    To setup spi for a atmega the teensy has different settings.
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    You have to send it out one or two bytes at time 0b00000000; Get a teensy 3.1 there cheap and use that code. That code will not work with arduino from what I see.
    I don't see how a arduino at 16 mhz can read a spi data of 40mhz clock rate. The teensy is 48 to 96 mhz chip it could meet the 40 mhz clock speed. and 32 bit packet size.
    https://github.com/xxxajk/spi4teensy3
    https://www.pjrc.com/teensy/teensyduino.html
     
    Last edited: Oct 9, 2015
  15. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Thank you sir.
    It looks Arduino Uno main MCU Atmega328 is much slower than Master ADAS1000.
    If so then what do you recommend me ? Arduino-Zero or Teensy 3.1?
     
  16. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    Teensy 3.1 Get the teensy 3.1 it's faster then the zero and from what i see the zero is not ready as it should be. So get the Teensy 3.1 it's cheaper and faster.
     
  17. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
  18. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    The last link was good if i had $199 to waste id get one and see what i could do..
     
  19. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Dear Sir,
    Besides Teensy 3.1 my boss suggest me to use TMS320F2812PGFA evaluation kit that is available now.
    Could you kindly cheek the datasheet page number 80 to 82? http://www.ti.com/lit/ds/symlink/tms320f2812.pdf
    Do you think this can be work with ADAS1000?

    Best regards
    Hasan
     
    Last edited: Oct 19, 2015
  20. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,807
    Likes:
    135
    Location:
    morristown,tn
    If you got $389 lol I'd go for the teensy it's like $20
    But yes it would work.
     
  21. MD MUBDIUL HASAN

    MD MUBDIUL HASAN New Member

    Joined:
    Sep 17, 2015
    Messages:
    14
    Likes:
    0
    Dear Sir,

    Beside Analog device, LT, TI, Freescale, Arduino, Renesas, I am working now STM32 with Ac6 STM32, that works by Ac6 STM MCU GCC compailer.


    Can you recognize these problem ?CDT console says,


    1. C:\STM32_toolchain\common\Drivers\CMSIS\Include/arm_math.h:6970:24: error: expected '=', ',', ';', 'asm' or 'attribute' before 'arm_bilinear_interp_q7'
    static __INLINE q7_t arm_bilinear_interp_q7(

    2. In file included from ..\startup\Src\stm32f0xx_hal_dac_ex.c:56:0: C:\Users\swend95_하산\Desktop\Design\notun_pj\Drivers\STM32F0xx_HAL_Driver\Inc/stm32f0xx_hal.h:528:29: error: unknown type name '__IO'
    void HAL_Delay(__IO uint32_t Delay);


    Lets assume that,

    In Properties > C/C++ Build > Settings > MCU GCC Compiler > Includes I have linked all necessary paths.

    In Properties > C/C++ general>Paths and symbols , I have added all HAL drivers,


    All right version of IDE,CDT,Java,Gcc has installed.


    Help me please.
     

Share This Page