2

Question is about using ADC AD7606 paired with Arduino (Arduino Mega). I can’t reach the stated speed of this bundle, the question is also whether it is possible or not. ADC output mode is 16-bit parallel. The physical connection corresponds to that in the examples using Mitov's Visuino. The sensor that sends data to the ADC is AC102-1a, connected via the recommended power supply circuit.

Compiled program code (provided below) that outputs the result of receiving data from one ADC port to the serial port monitor (disabled during speed testing, so as not to slow down the speed of output to the port). Also it has the ability to estimate the speed of the program, as a number of passes of the loop cycle per second.

There were some ways to increase the speed of the Arduino, replacing the standard functions digitalRead, digitalWrite, etc.

The speed of the program, without taking into account the full connection with the ADC (when disabling the waiting BUSY) reaches 150,000+ iterations per second, but if we providing full communication with the ADC (according to the scheme found in the examples of programs with this ADC – the sequence of setting levels on pins READ, BUSY, RESET, etc.), the speed falls to 1700 iterations per second.

This speed is achieved when over-sampling is enabled. If you turn it off, the speed becomes 40000 iterations per second, while increasing the amount of noise in the received signal.

The question is, where is the error in the binding of the ADC command sequence, why is the speed so low, and whether it is possible to achieve an increase in the speed of work, ideally reaching the stated 200k operations per second for this ADC.

#define RESET_PIN 4
byte pin4mask = (1 << 5);
#define RESET_SET_OUTPUT      DDRG  |=  pin4mask // Pin 4 OUTPUT
#define RESET_SET_INPUT       DDRG  &= ~pin4mask // Pin 4 INPUT
#define RESET_WRITE_HIGH      PORTG |=  pin4mask // Pin 4 to HIGH
#define RESET_WRITE_LOW       PORTG &= ~pin4mask // Pin 4 to LOW

#define CHIP_SELECT_PIN 3
byte pin3mask = (1 << 5);
#define CHIP_SELECT_SET_OUTPUT      DDRE  |=  pin3mask // Pin 3 OUTPUT
#define CHIP_SELECT_SET_INPUT       DDRE  &= ~pin3mask // Pin 3 INPUT
#define CHIP_SELECT_WRITE_HIGH      PORTE |=  pin3mask // Pin 3 to HIGH
#define CHIP_SELECT_WRITE_LOW       PORTE &= ~pin3mask // Pin 3 to LOW

#define READ_PIN 2
byte pin2mask = (1 << 4);
#define READ_SET_OUTPUT      DDRE  |=  pin2mask // Pin 2 OUTPUT
#define READ_SET_INPUT       DDRE  &= ~pin2mask // Pin 2 INPUT
#define READ_WRITE_HIGH      PORTE |=  pin2mask // Pin 2 to HIGH
#define READ_WRITE_LOW       PORTE &= ~pin2mask // Pin 2 to LOW

#define START_PIN 6
byte pin6mask = (1 << 3);
#define START_SET_OUTPUT      DDRH  |=  pin6mask // Pin 6 OUTPUT
#define START_SET_INPUT       DDRH  &= ~pin6mask // Pin 6 INPUT
#define START_WRITE_HIGH      PORTH |=  pin6mask // Pin 6 to HIGH
#define START_WRITE_LOW       PORTH &= ~pin6mask // Pin 6 to LOW

#define BUSY_PIN 7
byte pin7mask = (1 << 4);
#define BUSY_SET_OUTPUT      DDRH  |=  pin7mask // Pin 7 OUTPUT
#define BUSY_SET_INPUT       DDRH  &= ~pin7mask // Pin 7 INPUT
#define BUSY_WRITE_HIGH      PORTH |=  pin7mask // Pin 7 to HIGH
#define BUSY_WRITE_LOW       PORTH &= ~pin7mask // Pin 7 to LOW
#define BUSY_READ            bitRead(PINH, 4)

//PIN 14
byte pin14mask = (1 << 1);
#define DB1_SET_INPUT       DDRJ  &= ~pin14mask // Pin D14 to INPUT
#define DB1_READ            bitRead(PINJ, 1)

//PIN 15
byte pin15mask = (1 << 0);
#define DB2_SET_INPUT       DDRJ  &= ~pin15mask // Pin D15 to INPUT
#define DB2_READ            bitRead(PINJ, 0)

//PIN 16
byte pin16mask = (1 << 1);
#define DB3_SET_INPUT       DDRH  &= ~pin16mask // Pin D16 to INPUT
#define DB3_READ            bitRead(PINH, 1)

//PIN 17
byte pin17mask = (1 << 0);
#define DB4_SET_INPUT       DDRH  &= ~pin17mask // Pin D17 to INPUT
#define DB4_READ            bitRead(PINH, 0)

//PIN 18
byte pin18mask = (1 << 3);
#define DB5_SET_INPUT       DDRD  &= ~pin18mask // Pin D18 to INPUT
#define DB5_READ            bitRead(PIND, 3)

//PIN 19
byte pin19mask = (1 << 2);
#define DB6_SET_INPUT       DDRD  &= ~pin19mask // Pin D19 to INPUT
#define DB6_READ            bitRead(PIND, 2)

//PIN 20
byte pin20mask = (1 << 1);
#define DB7_SET_INPUT       DDRD  &= ~pin20mask // Pin D20 to INPUT
#define DB7_READ            bitRead(PIND, 1)

//PIN 21
byte pin21mask = (1 << 0);
#define DB8_SET_INPUT       DDRD  &= ~pin21mask // Pin D21 to INPUT
#define DB8_READ            bitRead(PIND, 0)

//PIN 22
byte pin22mask = (1 << 0);
#define DB9_SET_INPUT       DDRA  &= ~pin22mask // Pin D22 to INPUT
#define DB9_READ            bitRead(PINA, 0)

//PIN 23
byte pin23mask = (1 << 1);
#define DB10_SET_INPUT       DDRA  &= ~pin23mask // Pin D23 to INPUT
#define DB10_READ            bitRead(PINA, 1)

//PIN 24
byte pin24mask = (1 << 2);
#define DB11_SET_INPUT       DDRA  &= ~pin24mask // Pin D24 to INPUT
#define DB11_READ            bitRead(PINA, 2)

//PIN 25
byte pin25mask = (1 << 3);
#define DB12_SET_INPUT       DDRA  &= ~pin25mask // Pin D25 to INPUT
#define DB12_READ            bitRead(PINA, 3)

//PIN 26
byte pin26mask = (1 << 4);
#define DB13_SET_INPUT       DDRA  &= ~pin26mask // Pin D26 to INPUT
#define DB13_READ            bitRead(PINA, 4)

//PIN 27
byte pin27mask = (1 << 5);
#define DB14_SET_INPUT       DDRA  &= ~pin27mask // Устанавливаем пин D27 в режим INPUT
#define DB14_READ            bitRead(PINA, 5)

//PIN 28
byte pin28mask = (1 << 6);
#define DB15_SET_INPUT       DDRA  &= ~pin28mask // Устанавливаем пин D28 в режим INPUT
#define DB15_READ            bitRead(PINA, 6)

//PIN 29
byte pin29mask = (1 << 7);
#define DB16_SET_INPUT       DDRA  &= ~pin29mask // Устанавливаем пин D29 в режим INPUT
#define DB16_READ            bitRead(PINA, 7)

#define OS2 10
#define OS1 9
#define OS0 8
#define RANGE_PIN 11

const long interval = 1000;  

unsigned long previousMillis = 0;
unsigned long counter01 = 0;

void setup() {
  Serial.begin(9600);
  DB1_SET_INPUT;
  DB2_SET_INPUT;
  DB3_SET_INPUT;
  DB4_SET_INPUT;
  DB5_SET_INPUT;
  DB6_SET_INPUT;
  DB7_SET_INPUT;
  DB8_SET_INPUT;
  DB9_SET_INPUT;
  DB10_SET_INPUT;
  DB11_SET_INPUT;
  DB12_SET_INPUT;
  DB13_SET_INPUT;
  DB14_SET_INPUT;
  DB15_SET_INPUT;
  DB16_SET_INPUT;

  RESET_SET_OUTPUT;
  CHIP_SELECT_SET_OUTPUT;
  READ_SET_OUTPUT;
  START_SET_OUTPUT;
  pinMode (RANGE_PIN, OUTPUT);
  BUSY_SET_INPUT;

  RESET_WRITE_HIGH;
  delayMicroseconds(10);
  RESET_WRITE_LOW;

  CHIP_SELECT_WRITE_HIGH;
  READ_WRITE_HIGH;
  START_WRITE_HIGH;

  //Setting Oversampling Pins to Zero.
  digitalWrite(OS2, HIGH);
  digitalWrite(OS1, HIGH);
  digitalWrite(OS0, HIGH);

  digitalWrite(RANGE_PIN, HIGH);
}

void loop() {

  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    Serial.println( counter01 );
    counter01 = 0;
  }
  counter01 = counter01 + 1;

  /////////////////

  RESET_WRITE_HIGH;
  delayMicroseconds(1);
  RESET_WRITE_LOW;
  START_WRITE_LOW;
  START_WRITE_HIGH;

  while (BUSY_READ != LOW);
  CHIP_SELECT_WRITE_LOW;

  for (int AChannel = 0; AChannel < 1; ++AChannel)
  {
    READ_WRITE_LOW;
    uint16_t AResult = 0;
    if(DB1_READ == HIGH)
    { AResult |= ( 1 << 0 );}
    if(DB2_READ == HIGH)
    { AResult |= ( 1 << 1 );}
    if(DB3_READ == HIGH)
    { AResult |= ( 1 << 2 );}
    if(DB4_READ == HIGH) 
    { AResult |= ( 1 << 3 );}
    if(DB5_READ == HIGH)
    { AResult |= ( 1 << 4 );}
    if(DB6_READ == HIGH) 
    { AResult |= ( 1 << 5 );}
    if(DB7_READ == HIGH)
    { AResult |= ( 1 << 6 );}
    if(DB8_READ == HIGH) 
    { AResult |= ( 1 << 7 );}
    if(DB9_READ == HIGH)
    { AResult |= ( 1 << 8 );}
    if(DB10_READ == HIGH) 
    { AResult |= ( 1 << 9 );}
    if(DB11_READ == HIGH)
    { AResult |= ( 1 << 10 );}
    if(DB12_READ == HIGH) 
    { AResult |= ( 1 << 11 );}
    if(DB13_READ == HIGH)
    { AResult |= ( 1 << 12 );}
    if(DB14_READ == HIGH)
    { AResult |= ( 1 << 13 );}
    if(DB15_READ == HIGH)
    { AResult |= ( 1 << 14 );}
    if(DB16_READ == HIGH) 
    { AResult |= ( 1 << 15 );}

    READ_WRITE_HIGH;

    float AValue = float( int16_t( AResult ));
    if ( ! AChannel )
    {
      //Serial.println( AValue );
    }
  }
  CHIP_SELECT_WRITE_HIGH;
}
  • 2
    there is a typo in the #define READ_WRITE_LOW line ... in what universe is your English bad? certainly not in this one ... upvote – jsotola Mar 25 at 23:39
  • 1
    why don't you use PORTA and PORTC for the 16 bit data bus? .... then read bytes, instead of single bits – jsotola Mar 26 at 0:01
  • 1
    Your English is fine. upvote. – VE7JRO Mar 26 at 0:04
  • 1
    To debug cases like this, use an oscilloscope and watch the pins. I'm sure you will find that it is your software, the bit-wise reading, not the ADC. – the busybee Mar 26 at 7:31
  • 1
    the typo was corrected ... it was a missing comment delimiter – jsotola Mar 26 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.