Save Sampled data to my pc

What are you developing?
Post Reply
Ahmed Eltayeb
Posts: 5
Joined: Tue Aug 09, 2022 5:39 am

Save Sampled data to my pc

Post by Ahmed Eltayeb »

HI there
I am trying to read an ADC a parallel binary data https://datasheets.maximintegrated.com/ ... AX2771.pdf at the speed of 4MSPS with nucleo-H743ZI2. The data is sent with from 2 bins (I0,I1), CLK_out and GNS pin, my main goal is to read the data then save into a file.

Code: Select all

//#define CLK_OUT PC0 //A1
#define CLK_OUT_READ PB1 //A3
#define READ_I1 PA3 //A0
//volatile byte ledState = LOW;

void setup() {
  Serial.begin(4000000);
//  pinMode(CLK_OUT, OUTPUT);
  pinMode(CLK_OUT_READ, INPUT);
  pinMode(READ_I1, INPUT);
  attachInterrupt(digitalPinToInterrupt(CLK_OUT_READ), IDataRead, FALLING);
}
void loop() {
//  ledState = !ledState;
//  digitalWrite(CLK_OUT, ledState);
//  const uint8_t BIT = (GPIOB->IDR & 0x00000008) >> 1;
}
void IDataRead() {
uint8_t I1 = (GPIOA->IDR & 0x00000008) >> 3;
  Serial.println(I1);
}
the code works. Unfortunately I don't know if my code (nucleo Board) is fast enough and if I am getting a missing data.
Q1: how can I test if the the processer is fast enough?
Q2: Is the serial.Print() fast enough , if not what is a faster way to transmit and save the data ?
ps: the Code reads only 1 bit data from bin I1, the ADC can be set from 1 bit output and up to 3 bit
thank you in advance.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Save Sampled data to my pc

Post by ag123 »

USB full speed is normally 12 M bits per sec, that's the bandwidth, and normally with all the multiplexing between the keyboard, mouse and other peripherals, the host does all the polling and allocate slots, it is at best a few m(bits)ps.

So that in itself is a bottleneck, the connection between stm32 - adc is a different matter.

Things like this are normally done by DMA rather than interrupts or IO reads. there are various App notes
https://www.st.com/resource/en/applicat ... ronics.pdf
https://www.st.com/resource/en/applicat ... ronics.pdf

considered 'advanced' apps, and requires dedicated custom codes/programming for them

For those who would go the distance, it is to use usb high speed interface 480 mhz, which needs a dedicated ULPI high speed transceiver chip and a supported stm32 chip. At those speeds, it takes dedicated board design and chips. One is unlikely to get those speed using jumper wires.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Save Sampled data to my pc

Post by GonzoG »

1. You're reading 1 bit but sending 8 bits of data plus whole overhead data (i suspect "few" more bytes), and you're trying to do it 4M times per second.
You can simply check how fast it can send data to PC.

Code: Select all

uint8_t data = 1;
uint32_t start_time=millis();
for(uint32_t i=0;i<4000000;i++)
    Serial.print(data);
uint32_t end_time=millis();
Serial.println();
Serial.print("Time needed to send 4MB: ")
Serial.print(end_time-start_time);
Serial.println(ms);
If it's more then 1000 ms, then you cannot send 4M x 1B in 1 second.

But the bigger the data packet the faster it will actually be sent to PC as overhead will become smaller compared to data size.

2. If you're using USB to send data to PC, there is no baud rate settings. It always goes as fast as possible.
Ahmed Eltayeb
Posts: 5
Joined: Tue Aug 09, 2022 5:39 am

Re: Save Sampled data to my pc

Post by Ahmed Eltayeb »

ag123 wrote: Thu Aug 18, 2022 10:57 am USB full speed is normally 12 M bits per sec, that's the bandwidth, and normally with all the multiplexing between the keyboard, mouse and other peripherals, the host does all the polling and allocate slots, it is at best a few m(bits)ps.

so that in itself is a bottleneck, the connection between stm32 - adc is a different matter.
currently I am using CDD native USB port (with 480Mbit/s transmission ) with a high speed USB cable to transmit the data from nucleo to my pc using the function (SerialUSB.write()).
The connection goes link this (FrontEndOutput(I0,I1,CLK_OUT) to NucleoBoard(bins) to PC through USB)
my current issue is the data that I am receiving does not make no sense.
the code reads pin I0 and I1 when the CLK_out is in falling edge (attachInterrupt(digitalPinToInterrupt(CLK_OUT_READ), IDataRead, FALLING);)
my CLK_out speed is ranges from 4MSPS-44MSPS, I can print data then process it in matlab.
my concern is that the data is read then saved with different sampling frequency than the one sent from ADC because the interrupt is not fast enough.

Code: Select all

#define READ_I0 PA3 //A0
#define READ_I1 PC0 //A1
#define CLK_OUT_READ PB7 //D0
void setup() {
  SerialUSB.begin(9600);
  pinMode(READ_I1, INPUT);
  pinMode(READ_I0, INPUT);
  pinMode(CLK_OUT_READ, INPUT);
  attachInterrupt(digitalPinToInterrupt(CLK_OUT_READ), IDataRead, FALLING);
  

void IDataRead() {
I = ((GPIOC->IDR & 0x00000001) << 1) + ((GPIOA->IDR & 0x00000008) >> 3); // Read I0+I1
//print I data to USB in its intger value
switch(I){ 
  case 0:
    SerialUSB.write(1);
  break;
  
  case 1:
    SerialUSB.write(3);
  break;
  
   case 2:
    SerialUSB.write(-1);
  break;
  
  case 3:
    SerialUSB.write(-3);
  break;
}
I am very new to this, I would really appreciate any kind of help I can get.
I have been stuck for the past few weeks
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Save Sampled data to my pc

Post by ag123 »

DMA would help get something close to those speeds, refer the 2 App notes given earlier.
Those would detour from plain 'arduino' api and it would require working with the hardware directly.
e.g. access the registers directly. Keep the reference manual for your stm32 chip handy, they normally have verbose documentations on the hardware, dma, registers etc.
https://www.st.com/resource/en/referenc ... ronics.pdf
Perhaps things like HAL etc can help, but I'm not too familiar.

In this little project, on a stm32f401 i got about 5 MBps. that I did by setting the registers and letting DMA read it back.
maybe it could be higher, but I did not find out, it is just a rough test just to see that the app works.
viewtopic.php?f=10&t=116
I'd think hardware on different processors varies, other processors in the series or maybe h7 etc could be more performant on the IO.
at high speeds, signal quality and everything matter, I'd think even some stray capacitances scattered around could heavily impact data transmission.

do review documentation for your board as well
https://www.st.com/en/evaluation-tools/ ... l#overview
various stm32 mcus support a high speed ULPI transceiver, but that it is a separate component that needs to be built onto the main board with its own requirements.
Post Reply

Return to “Projects”