danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 13, 2024 12:15 am

I tried compiling the code, but I was encountering a hardfault
Hardfault on compile ? Which one.

I check it again and it's compile ok

Code: Select all

daniel@benchpi4:~ $ git clone https://github.com/danjperron/picoADC_UDP
daniel@benchpi4:~ $ cd picoADC_UDP/
daniel@benchpi4:~/picoADC_UDP $ cd picoADC_USB/
daniel@benchpi4:~/picoADC_UDP/picoADC_USB $ mkdir build
daniel@benchpi4:~/picoADC_UDP/picoADC_USB $ cd build
daniel@benchpi4:~/picoADC_UDP/picoADC_USB/build $ cmake ..
daniel@benchpi4:~/picoADC_UDP/picoADC_USB/build $ make
Did you setup the C-SDK correctly?

Once you transfered the uf2 to the pico the device for the pico usb should be /dec/ttyACM0

Just do

Code: Select all

cat /dev/ttyACM0
And it should echo blocks of characters all the time.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 14, 2024 6:12 pm

Hello Dan,
I followed all your instructions and checked my entire environment but I am still kept receiving a hardfault whenever I tried sending to usb, I debugged it and saw that the problem was with the base64_encode() function whenever i tried to validate the data with this fault.
Screenshot 2024-02-14 120827.jpg
Screenshot 2024-02-14 120827.jpg (97.38 KiB) Viewed 508 times
This kept happening till I changed the block size to 10, chunk size to 10 and chunk byte size to 20 then I was able to step further but i face another hard fault when the data was going into puts_raw. After further debugging I saw there was a problem with the encoding as when the out_chars was being validated in the stdio_.
Screenshot 2024-02-14 120630.jpg
Screenshot 2024-02-14 120630.jpg (90.97 KiB) Viewed 508 times

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 14, 2024 7:07 pm

First does it work with the original CHUNK and BYTE SIZE ?

I tweaked these parameters for maximum memory size and maximum transfer ratio.

B.T.W. SAMPLE_CHUNK_SIZE and SAMPLE_BYTE_SIZE need to be divisible by 6.

base64 takes 3 bytes (8 bits) to create 4 bytes( 6bits). then it needs 3 bytes. and each sample is 2 bytes (2x3)
CHUNK_SIZE 10 and BYTE_SIZE 20 should not work

Try CHUNK_SIZE 12 and BYTE_SIZE 24

Using this so small chunk size will reduce the transfer rate be a lot! Maybe by a factor of 10.

Also there is a lot of manipulation to set the DMA in daizy chain. With this small dma transfer you could get overrun.

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Thu Feb 15, 2024 2:56 am

From my PI5 fresh SD Card I install the newest pico C-SDK and clone my github.

I change the fifoblock header to

Code: Select all

#define SAMPLE_CHUNK_SIZE  12
#define SAMPLE_BYTE_SIZE   24
Recompile and upload the uf2.

Then I type

Code: Select all

cat /dev/ttyACM0
and got

Code: Select all

daniel@Pi5:~ $ cat /dev/ttyACM0 
1E31TAAAoQOgA50DnAObA5kDmAOXA5YDlgOVA5UD

EE71TAAAlAOUA5QDngOpA6UDrQOqA6wDqQOlA6ID

TE71TAAAoAOdA5sDmgOZA5gDlwOWA5UDlAOUA5UD

iE71TAAAlQOUA5YDpAOoA6UDrAOuA6oDpgOjA6ED

xE71TAAAngOdA5wDmgOZA5gDlgOWA5YDlQOVA5UD

AE/1TAAAlAOVA5UDnAOqA6YDqwOpA6wDqQOmA6MD

So If I decode the first line

Code: Select all

daniel@Pi5:~ $ echo 1E31TAAAoQOgA50DnAObA5kDmAOXA5YDlgOVA5UD | openssl enc -base64 -d | hexdump -C
00000000  d4 4d f5 4c 00 00 a1 03  a0 03 9d 03 9c 03 9b 03  |.M.L............|
00000010  99 03 98 03 97 03 96 03  96 03 95 03 95 03        |..............|
0000001e
The first 6 bytes are the time stamp in microsecond (48bits).
after that you have 12 ADC samples of 16 bits.

This is exactly what we set the header to be 48bits timestamp + (12 samples of 24 bytes)

If you decode the second line you will get a timestamp with an offset of 60us (0x4cf54e10-0x4cf54dd4)
60us for 12 samples which is 200K samples/sec.

N.B. 48bits timestamp was choosen because base64 use multiple of 24bits and 8 years timers is good enough.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Mon Feb 19, 2024 9:42 pm

HI
I have tried your code. We can collect the data in a .dat file. Since data in .dat file is in byte format, we are converting it to integers to see whether the values make sense.
I also simultaneously ran the adc code of pico-c-sdk-adc example to see what are the integers values they give as you can see in the screen shot below:
20240219_15h34m46s_grim.png
20240219_15h34m46s_grim.png (191.92 KiB) Viewed 445 times
But the 16 bit integer values the adc-c-sdk code returns and what i get when I am using .dat file method of yours dont make sense. Surely I am doing something wrong when I am converting data to integers from .dat file.

We are using the.dat file and taking two bytes at a time to convert it to integers and appending it in a csv file.

import binascii
import base64
import struct
import sys
import csv


n=6
dat_file_path = 'data.dat'
csv_file_path = 'integers.csv'
list1=[]

with open(dat_file_path, 'rb') as dat_file:
while True:
chunk = dat_file.read(2)
if not chunk:
break
list1.append((int.from_bytes(chunk, byteorder='big')))

with open(csv_file_path, 'w', newline='') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(list1)

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Mon Feb 19, 2024 9:53 pm

Code: Select all

>>> hex(45571)
'0xb403'
>>> hex(45827)
'0xb303'
>>> hex(45571)
'0xb203'
>>> hex(46339)
'0xb503'
>>> print(0x3b2,0x3b4,0x3b5)
946 948 949
Small error on your part is little endian.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 20, 2024 7:17 pm

Hi Dan,
We are finally sampling properly but the sampling rate seems to be very low. We are seeing 21k samples in 5 seconds worth of data but it should be almost 1 million samples in that time. Am I missing something?

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 20, 2024 8:14 pm

Hi Dan,
We are finally sampling properly but the sampling rate seems to be very low. We are seeing 21k samples in 5 seconds worth of data but it should be almost 1 million samples in that time. Am I missing something?

Well a lot of things that I don't know about how you are sampling the data?

1 - Are you using my original version in folder ./picoADC_USB?
Like I said if you modify the SAMPLE_CHUNK_SIZE and SAMPLE_CHUNK_SIZE and set them to 12 and 24 well you reduce the transfer rate about 10 folds. Bigger the chunk last handling between packet!

2- The USB speed transfer by itself!
There is a maximum speed transfer from the USB serial rate. I found out that the PI5 is slower on USB serial transfer than the Pi4.

3- And of course the storage device you are using . If it is a "Pi" than a fast SD card is needed.

Each packet contains timestamp . Check if you are missing some by comparing timestamp!

Modify the "usbtodisk.py" to save nothing but check the timestamp only. This will give you an indice about the transfer rate without saving it.

B.T.W. For all the test I did the best way was the method to save on SDcard using the SDIO mode.

A way to test the data is to store the incoming USB serial port data to ramdisk .
copy everything from the USB serial to a file on the ramdisk.
ex: create a 250 MB ramdisk on rasberry Pi

Code: Select all

daniel@Pi5:~ $ sudo mkdir /ramdisk
daniel@Pi5:~ $ sudo chmod 777 /ramdisk
daniel@Pi5:~ $ sudo mount -t tmpfs -o size=250m aramdisk /ramdisk
daniel@Pi5:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           805M  6.0M  799M   1% /run
/dev/sda2        29G   12G   16G  43% /
tmpfs           4.0G  432K  4.0G   1% /dev/shm
tmpfs           5.0M   48K  5.0M   1% /run/lock
/dev/sda1       510M   75M  436M  15% /boot/firmware
tmpfs           805M  144K  805M   1% /run/user/1000
aramdisk        250M     0  250M   0% /ramdisk
daniel@Pi5:~ $
Now /ramdisk folder is a ramdisk
Just transfer everything from the USB port to a file in the ramdisk folder

Code: Select all

cat /dev/ttyACM0 >/ramdisk/capture1.txt
Wait 5 seconds and press ctrl-c.
Now analyze what you have on /ramdisk/capture1.txt.
This way you exclude the speed needed for the python script to decode the serial input and the transfer to store to the SDCard.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 21, 2024 8:09 am

Hi, Thanks for all your help. To be on the same page, I am using your picoADC_USB code and that is supposed to sample at 200ksample/sec and transfer it over the USB to pi4 right (mi pi 4 has sdc card)?
Each block has 600 samples, so that means for each second I will need around 333 blocks of data, right?
But when the python code saves data in .dat file, it seems it is not getting 333 blocks of data for each second.
I will check ramdisk to see whether the usb actually gets all the data for each second or not. Againn thanks for your input.
Did you acquire and transfer 200ksamp of data for each second over the usb?

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 21, 2024 1:50 pm

Did you acquire and transfer 200ksamp of data for each second over the usb?
Yes I did on Pi4 but not on PI5 ;-(

It is possible to increase the transfer rate by using only the resolution of ADC which is 12bits.

Right now a block of 600 samples is 1609 bytes with base64 but if we are using the 12bits then a block in base 64 will be 1209 bytes which is ~40% faster.

I will add the code into the github later. I will include a python script to check the integrity of the transfer file. It will report how many block is out of sync.

regards,

Daniel

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 21, 2024 4:21 pm

I am also using pi 4.
I dont know why i cant sample at 200k sample per sec. or may be I am doing it but the usb is not transferring 200ksample/sec. It is 333 blocks per second right to transfer 200ksample/sec?

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Wed Feb 21, 2024 7:03 pm

Ok I modified the PicoADC_USB to output 12bits instead of 16 bits.

I also removed a not needed '\a' on the output.

I added a #define in picoADC_USB.c to specify if you want 16 bits or 12 bits transfer.

On 16 bits you send 1609 bytes in base 64 to the Pi4.
On 12 bits you send 1209 bytes in base64 to the Pi4. This is an increase of 40%

I also tried to transfer 250K samples per second on both mode and my Pico + Pi 4 were able to handle the 16 and 12 bits mode transfering the data into my SDCard.

From a 7 minutes run I got 2 missing packets

Code: Select all

daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB $ time ./usbtodisk.py >adcdata.bin
251113784    0   9000
476497783    0   197999
^C
Continuous valid packet : 140936
Missing sync packet : 2
^C

real    7m4.029s
user    2m7.972s
sys     0m5.213s
daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB $ ls -l *.bin
-rw-r--r-- 1 daniel daniel 169126800 Feb 21 13:43 adcdata.bin
daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB $ bc
The let's do math!

200 000 samples / sec is ~333 blocks/sec
Once decompress I should have for 7m4.029s a total of
(200Ksamples/sec * (7*60+4) * 2 bytes/sample) = ~169 600 00 bytes

And this is roughtly what I got! Timing count the startup and the end of program but it is in the bulk part.

To prevent the missing packet we have some possibilities.

1 - Only run the console. Disable the gui (No Desktop to increase performance).
2 - Save on RAMDISK and then transfer to SDcard or USB disk. if you have a PI4 with 8G you have more than 2 hours of data collection.
3 - Convert the usbtodisk.py in C/C++. The 12bits handling to 16bits conversion is quite slow on python.

Also I notice that if you store to USB memory stick it will slow down the USB and you will loose packet!

Next I will try the ramdisk for one hour and see If the transfer using "cat" by itself loose packet

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Thu Feb 22, 2024 1:33 am

I added usb2bin.c application.

This application will convert the base64 12bits data into a binary file where each sample points are unsigned short (16bits).

Wow! with this I was able to use the Pi5 at 200Ksamples/sec and store it into the USB3 memory stick.

On the Pi4 I was able to do 250K samples/sec without loosing any block at all!

To compile

Code: Select all

gcc -o usb2bin usb2bin.c
and to run just use the cat command and pipe it!

Code: Select all

cat /dev/ttyACM0 | ./usb2bin >capture.bin
N.B. the usb2bin only support the 12bits mode! You will need to compile the pico program with

Code: Select all

#define USE_12BITS
line 73 in picoADC_USB.c

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Thu Feb 22, 2024 6:37 pm

I ran the ADC for 7 minutes on my setup and have saved the data.dat file using your usbtodisk.py program and attached the link to the drive folder containing the data.dat file. Could you please verify the data that I have received is correct.
Google Drive Link:
https://drive.google.com/file/d/1VUpLo7 ... sp=sharing

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Thu Feb 22, 2024 8:27 pm

The data format is correct but,
ADC0.JPG
ADC0.JPG (65.27 KiB) Viewed 281 times
N.B. Step aren't in 5 us interval
This file is only 3.5MB which gives only 1811847 data points in 7 minutes.

Code: Select all

daniel@linuxserver:~/pico/picoADC_UDP/picoADC_USB$ ./bin2csv data.dat  /dev/null
.........................................................................
Got 1811847 data points
All Done!
This mean that your sample rate is around 4313.92 sample/sec

I can't figure out Why your Pi4 is so slow. I thing that I will try with my RaspberryPi B ver 1.1 to see how slow it is.
What is your SD card model and speed ? Is the boot drive the SD card?
I hope that you aren't using an external USB memory stick to store the data ?
Are you in Desktop mode or console mode?
Did you try using the ramdisk version?
Do you have something else running on that Pi4?

B.T.W. this is a little program to convert the binary output to a csv readable text file.
First parameter is the Input binary file
Second parameter is the CSV text output File.
Third parameter is the maximum number of data point to output. If omitted there is no maximum count. (Excel max is 1048576)

bin2csv.c

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char * argv[])
{
  FILE * src=NULL;
  FILE * dst=NULL;
  unsigned short buffer[2048];
  size_t bufferSize;
  int loop;
  int Maximum=0;
  int Count;
  int RunFlag=1;
  if((argc!=3) && (argc!=4))
  {
    printf("\nUsage:\n       bin2csv   PicoADCDatfile    CSVFile.txt  maximum_count\n\n");
    return -1;
  }

  src = fopen(argv[1],"rb");
  if(src == NULL)
   {
    printf("Unable to open %s\n",argv[1]);
    return -2;
   }

  dst = fopen(argv[2],"wt");
  if(dst == NULL)
   {
    printf("Unable to create %s\n",argv[2]);
    fclose(src);
    return -3;
   }

 if(argc==4)
    Maximum = atol(argv[3]);

  Count=0;
  while(RunFlag)
  {
    // get 2048 word to fill buffer
    //
    bufferSize = fread(buffer,2,2048,src);
    if(bufferSize==0)
       break;
   for(loop=0;loop<bufferSize;loop++)  // we read short than it is 2 bytes
   {
      fprintf(dst,"%d\n",buffer[loop]);
      Count++;
      if(Maximum > 0)
      {
        if(Count >Maximum)
         {
           RunFlag=0;
           break;
         }
      }
   }
  printf(".",bufferSize);  // this is just an indicator
  }
  printf("\nGot %d data points\n",Count);
  printf("All Done!\n");
  fclose(src);
  fclose(dst);
  return 0;
}
Last edited by danjperron on Thu Feb 22, 2024 9:26 pm, edited 2 times in total.

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Thu Feb 22, 2024 9:13 pm

An alternative will be to use another computer and check what is the culprid!
I tend to be pointing to your Pi4 which is maybe loaded with a lot of stuff, maybe too much peripheral on the USB port or a very slow SD card.

This is on my second Pi4 which perform exactly the same has the first one

In 7Min 42 seconds I got 177MB of data of 92596200 data points
This is exactly 200000 samples/sec

Code: Select all

daniel@Pi4B:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 12 (bookworm)
Release:        12
Codename:       bookworm
daniel@Pi4B:~ $ uname -a
Linux Pi4B 6.1.0-rpi7-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.63-1+rpt1 (2023-11-24) aarch64 GNU/Linux
daniel@Pi4B:~ $ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.6Gi       235Mi       5.6Gi       1.2Mi       1.9Gi       7.4Gi
Swap:           99Mi          0B        99Mi
daniel@Pi4B:~ $
daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB$ time cat /dev/ttyACM0 | ./usb2bin >capture5.bin
^C
154326 block in sequence
0 block out of sequence

real    7m42.980s
user    0m1.839s
sys     0m10.562s
daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB$ ls -l -h capture5.bin
-rw-r--r-- 1 daniel rad 177M Feb 22 15:49 capture5.bin
daniel@Pi4B:~/pico/picoADC_UDP/picoADC_USB$ ./bin2csv capture5.bin /dev/null
Got 92596200 data points
All Done!
daniel@Pi4B:~ $ awk '{printf "%f\n", 92596200 / ( 7*60+42.98)}'

200000.431984

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Fri Feb 23, 2024 1:16 am

@Pranjol93 something is wrong with your setup.

I tried my old Raspberry Pi B with an overclock at 900MHz and I was able to get 120K samples/sec without any lost.
B.T.W. This Pi has only 256MB and it's a single core.
PicoADCPI1B.jpg
PicoADCPI1B.jpg (34.79 KiB) Viewed 257 times

Code: Select all

daniel@PiB:~ $ cat /proc/cpuinfo
processor	: 0
model name	: ARMv6-compatible processor rev 7 (v6l)
BogoMIPS	: 697.95
Features	: half thumb fastmult vfp edsp java tls 
CPU implementer	: 0x41
CPU architecture: 7
CPU variant	: 0x0
CPU part	: 0xb76
CPU revision	: 7

Hardware	: BCM2835
Revision	: 0003
Serial		: 0000000013e6320e
Model		: Raspberry Pi Model B Rev 1
daniel@PiB:~ $ free -h
               total        used        free      shared  buff/cache   available
Mem:           176Mi        34Mi        79Mi       0.0Ki        62Mi        93Mi
Swap:           99Mi       5.0Mi        94Mi
daniel@PiB:~ $

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Fri Feb 23, 2024 2:39 am

ok just to check if the transfer works in reality I just made a small setup using a TL555C with a small 0.1uF and 4k7 resistor to oscillate.
I connect the pin 2 of the 555 to ADC0 and read the signal.
tl555_2.JPG
tl555_2.JPG (102.87 KiB) Viewed 250 times
From this signal I was able to create this graphic using excel.
TL555_OSC.jpg
TL555_OSC.jpg (35.84 KiB) Viewed 249 times
And this is my oscilloscope
pic_319_1.gif
pic_319_1.gif (18.29 KiB) Viewed 250 times

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Fri Feb 23, 2024 5:03 pm

Hi
Thanks a lot for your help. Let me check few details, I will get back to you. Thanks again.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 5:39 am

Hi
Thanks a lot.
I used pi 5 and it worked flawlessly.
Pi 4 was the culprit.
I used usb2bin.c to save in a binary file and used bin2csv.c to save the raw voltage values in csv.
Then i tried to scale it back to original voltage values. The signal I was sampling was a sinusoidal signal (10 Khz) between +2.3V and +40 mV.
But after I scaled it back by multiplying 3.3/2^12 factor ( i belive I need to multiply by this factor with the raw adc values, as pico operates between 0-3.3v and 12 bit resolution)
But the problem is I am not getting the +2.3 volt maximum or minimum. It seems my maximum is 1.9 v. I am losing accuracy in amplitude.
Am I multiplying raw adc values with correct factor? (my pico has 12 bit precision, and it should be 2^12 right? )
Did your signal amplitude matched with your collected signal? ( i believe it did)

I connected the signal generator directgly with my pico.
And connected the pico directly with my pi5.
( do i need to connect any resistor before collecting data, or I am converting it back to original voltage with wrong factor)

Thanks a lot again for your help.

This is the signal i acquired with pico and pi5, which has lost accuracy inn amplitude. I have the raw adc values using your bin2csv.c file.
https://drive.google.com/file/d/1M8BVqJ ... sp=sharing

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 2:15 pm

I'm glad that you were able to figure it out.

The strange thing is that both of my Pi4 are faster on the USB transfer than my Pi5.


Two things that you should check nn the Pico.

1 - The Vref of the pico is from the 3.3V supply filter by a resistor and a capacitor. It is noisy and it could be not exactly 3.3V. If you want better performance use a shunt precision voltage reference like the LM4040 (Pico datasheet page 18).

2- Input impedance play a role on the input signal. What was to output impedance of your signal. The ADC Input impedance is around 100K ohm.

From Vout = Vin *(R1/R1+R2)

It looks like that your output impedance is around

1.9V = 2.3V * 100K / Rout + 100K => Rout = ~20K

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 4:08 pm

Is my scaling factor correct?
3.3/2^!2??

danjperron
Posts: 4743
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 5:50 pm

if 2^12 means 2 power 12 it is ok in excel!

but in C or Python 2^12 is 14. This means 2 xor 12

use 3.3/4095 instead if you are using C or python.

carlk3
Posts: 210
Joined: Wed Feb 17, 2021 8:46 pm

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 6:30 pm

In the world of DSP, the usual approach is to convert the ADC input into a normalized form like Q15, which is simply an int16_t interpreted as a real number between -1 and (almost) +1. This maximizes the resolution for any further processing. Since you're usually working with a linear time-invariant system, you can save the scaling to physical units until the very end; for presentation or whatever. For a 12-bit ADC, a simple (i.e., fast) subtraction and bit shift should do the conversion. E.g,

Code: Select all

q15_t sample = ((int16_t)ADC_code - 2048) << 4;
In this form, you can easily process the data with CMSIS-DSP (see CMSIS-DSP Usage/Installation).

Note: there is a Python Wrapper for CMSIS-DSP, but I haven't tried it on the Pico.
Last edited by carlk3 on Tue Feb 27, 2024 11:18 pm, edited 2 times in total.

Pranjol93
Posts: 57
Joined: Thu Nov 30, 2023 8:38 pm

Re: Transfer data over wifi for pico for a high sampling rate

Tue Feb 27, 2024 7:48 pm

danjperron wrote:
Tue Feb 27, 2024 5:50 pm
if 2^12 means 2 power 12 it is ok in excel!

but in C or Python 2^12 is 14. This means 2 xor 12

use 3.3/4095 instead if you are using C or python.
Hi,
In your experiment did you lose any amplitude accuracy?
My vref is 3.3 volt. would you mind checking the file , whether you get maximum voltage 2.3 volt after conversion. I have added the file.
https://drive.google.com/file/d/1M8BVqJ ... sp=sharing

Return to “General”