6

I'm working on a project of Ultrasonic Flow Meter with TDC-GP22 using Arduino UNO. I used the library of leokoppel

In my code,the configurations of the registers are copied from the Application Note of GP22, from page 22 to page 25. I didn't use the temperature sensor so I jumped those steps related to that. No calibration neither. I just want to get some results of time of flight to be able to calculate the distance between two sensors for now.

My code for test:

#include "GP22.h"
#include <SPI.h>
#include <avr/io.h>

/*
 *  
 * Test setup (Arduino Uno, through 5->3.3V level shift)

 *     10 -> SS 
 *     11 -> MOSI
 *     12 -> MISO
 *     13 -> SCK
 *     2  -> INT
 *     5V -> VCC
 *     GND -> GND
 *     4 -> DS18B20 temperature sensor (optional)
 */

const bool DEBUG = 1;
const int FAST_MODE = 1;
const int PIN_INT = 2;

GP22 tdc(PIN_INT, DEBUG);

float cycleFactor_ns = 0; 

void setup() {

  Serial.begin(115200);
  Serial.println("Go !");

  tdc.init();

  tdc.writeRegister(0, 0x430BE800);
  tdc.writeRegister(1, 0x21444000);
  tdc.writeRegister(2, 0xA0138800);
  tdc.writeRegister(3, 0xD0A24800);
  tdc.writeRegister(4, 0x10004000);
  tdc.writeRegister(5, 0x40000000);
  tdc.writeRegister(6, 0xC0C06100);

  tdc.printConfigRegisters(); 

  byte a = tdc.readRegister(READ_REG_1);             

  Serial.println(a,HEX);
  Serial.println("Test communication: ");
  Serial.print(tdc.testCommunication());
 }  

void loop() {

  tdc.sendOpcode(OPCODE_INIT);
  tdc.sendOpcode(OPCODE_START_TOF_RESTART);
  tdc.waitForInterrupt(10000000);

  delay(20);

  Serial.println(tdc.readRegister(READ_RES_3),HEX);
}

From oscilloscope I got the right number of fire pulses(20) with right frequency(1MHz): Signal (the blue one is the signal of transmitter before amplification, green one is after amplification, yellow one is the signal of receiver)

But what I got from the code:


Go !

attached pinChangeISR_debug

Register 0: 0x430be800

Register 1: 0x21444000

Register 2: 0xa0138800

Register 3: 0xd0a24800

Register 4: 0x10004000

Register 5: 0x40000000

Register 6: 0xc0c06100



21

Test communication: 

\/Test took 180 us

1

69978000

69978000

69978000

69978000

69978000

69978000

69978000

...

21 is the first byte of register 1, and 1 is the result of testcommunication(). These two means the test of communication is successful. But the results of reading RES_3 are always the same, and the waitForInterrupt() doesn't work(maybe the code shouldn't be written like this) -- Timeout all the time.

What I expect, of course, is the result can change each time it measures.(impossible to get exactly the same measurement of ToF all the time)

Any help appreciated!

2
  • Have you solved your problem? I am also interested to read result of TDC GP22.
    – Tom
    Commented Sep 29, 2021 at 11:01
  • I've been working with the GP22. I was wondering if you ever got yours to work. I know the datasheet says to generate a start and stop pulse across the start and stop pins, that is the route I went. I was wondering if you've made any progress since your last post about it?
    – Digit
    Commented Oct 31, 2022 at 5:47

1 Answer 1

0

First of all, the example in the document are for STM32. Since you need to do debugging, you could start with the following:

  1. Verify that the register configurations are correct and suitable for your specific setup. Since you mentioned copying from the Application Note, ensure that no steps were missed. Make sure that the configurations of your registers (0x430BE800, 0x21444000, etc.) are accurate for your application for the Arduino Uno. Any mismatch here can cause incorrect behavior.

  2. Ensure the interrupt is correctly set up and handled. The waitForInterrupt function might need to be reviewed or modified to correctly capture the interrupt.

  3. Check if the results reading method is correct and if you need to clear any flags or perform additional steps after reading the results. This might get your code stuck.

Not the answer you're looking for? Browse other questions tagged or ask your own question.