Crosstalk and sample frequency issues on a pressure sensor matrix

Post here first, or if you can't find a relevant section!
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by fredbox »

You may want to consider refactoring the code to use arrays of binary values instead of booleans.
I would expect this to be much more efficient, as the arrays are simplified from two dimensions to one.

Code: Select all

const uint32_t outmuxChannel[] =
{
  0B0011111111110000, //channel 0
  0B0011111111111000, //channel 1
  0B0011111111110100, //channel 2
  0B0011111111111100, //channel 3
  0B0011111111110010, //channel 4
  0B0011111111111010, //channel 5
  0B0011111111110110, //channel 6
  0B0011111111111110, //channel 7
};
uint32_t is the native storage type and uses less code than uint16_t.

Printing 8 values to USB serial:

Code: Select all

16368
16376
16372
16380
16370
16378
16374
16382
Elapsed time: 112 microseconds
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by GonzoG »

muh89 wrote: Sat May 22, 2021 3:52 pm Thank you, really appreciated. I just tried your code but nothing changed, always around 1500ms for one scan. :?
Until you use HAL / LL to do analog readout you won't gain much speed.
On F411 single analogRead() needs about 60us, so over 1s just to read all sensors. I suspect that on F746 it isn't much faster.
muh89 wrote: Sat May 22, 2021 3:52 pm Thanks! I like the idea of analog switches, I will try it too but I need to print a new PCB. What concerns analog side: I really don't understand why connecting MUXes to different analog pins should reduce the time.
Multiplexers need quite significant time to switch between channels. The more channel switching the more time you waste.
In case when you use analogRead() it actually doesn't really matter as analogRead() needs some time to initialize ADC, but with faster analog readout you will probably need to add some delay between switching channel and reading data.
muh89
Posts: 6
Joined: Mon May 17, 2021 7:48 pm

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by muh89 »

Thank you all for the help. It seems I have a lot of work to do:

-pulldown resistors on all columns
-optimize the code
-learn to use HAL or LL functions for analog readout (may you show me some examples?)
-(and maybe shift registers...)

Give me few weeks and I'll come back to check!
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by GonzoG »

muh89 wrote: Sun May 23, 2021 10:39 am -learn to use HAL or LL functions for analog readout (may you show me some examples?)
-(and maybe shift registers...)
I found 2 topic here on forum, but both are for f1xx line of MCUs:
viewtopic.php?f=41&t=110
viewtopic.php?f=7&t=138
mosarp87
Posts: 1
Joined: Thu Nov 04, 2021 1:30 pm

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by mosarp87 »

Hello Sir,

I am just an amateur student interested in this same topic. I've been struggling to make one these circuits. I watched countless times the 2 links you provided in your message. Due to my lack of knowledge, I made my circuit without multiplexers and diodes wrt to this basic application link;

https://www.kobakant.at/DIY/?p=7943

I made a 16x16 pressure matrix according to these explanations(also Arduino Mega has 16 Analog Inputs) but the system works under full of crosstalks and unwanted noise. Now I intend to make a new 32x32 pressure matrix just like in your video.

Could you please share your experience (Arduino code/Stm/Processing code and circuit schema) with me?

Any help would be appreciated, thanks in advance.


muh89 wrote: Sat May 22, 2021 8:43 am Hello!

I made a pressure sensor matrix that has a first layer of 96 copper tape strips (rows), a velostat (semi-conductive material) layer and 176 copper tape strips (columns) for a total of 176x96=16896 sensors! I based my work on this two designs: https://www.youtube.com/watch?v=0uPZwMg5B3k and https://www.youtube.com/watch?v=xvmgzwjKnN4&t=297s.

I'm using a nucleo-144 f746zg board with 11 multiplexers (16 channels) connected to all 176 columns through diods. I'm sending 3,3V at one column at a time and reading the signal of one row at a time through other 6 multiplexers connected to the same ADC pin. Each row is also connected to ground through 1k resistors. The data is transmitted through the st-link USB of the nucleo board to my Mac and a little Processing sketch creates a heatmap from the acquired data. This is a simplified drawing of the wirings:
schematics.jpeg

At first I create a small 16x16 project with Arduino Uno, than a bigger 32x32 project with both Arduino Mega or Nucleo-144 f746zg. All these projects worked perfectly (as you can see from this little video: https://drive.google.com/file/d/18HQxM9 ... sp=sharing) but this bigger version has two major issues:
-crosstalk (or ghosting? i don't know how to call it) along the rows being pressed as you can see from this image of my left hand leaning on the mat
Schermata 2021-05-19 alle 10.02.30.png
-sampling frequency. It takes about 1500ms to read all the 16896 sensors and transmit the readings to my Mac. It means 0,7 scans per second when i need, at least, 5 or 10 scans per second.

This is the Arduino IDE code:

Code: Select all

//Mux control pins for analog signal
const byte s0 = PB9;
const byte s1 = PD8;
const byte s2 = PA5;
const byte s3 = PA12;
const byte eninMux1 = PB6;
const byte eninMux2 = PB11;
const byte eninMux3 = PA7;
const byte eninMux4 = PB12;
const byte eninMux5 = PA6;
const byte eninMux6 = PA11;
const byte SIG_pin = A0;

//Mux control pins for Output signal
const byte w0 = PC7;
const byte w1 = PB2;
const byte w2 = PA9;
const byte w3 = PB1; 
const byte enoutMux1 = PA2;
const byte enoutMux2 = PF5;
const byte enoutMux3 = PA10;
const byte enoutMux4 = PC4;
const byte enoutMux5 = PB3;
const byte enoutMux6 = PB5;
const byte enoutMux7 = PB13;
const byte enoutMux8 = PB4;
const byte enoutMux9 = PB14;
const byte enoutMux10 = PB10;
const byte enoutMux11 = PB15;
const byte OUT_pin = PA8;


//Arrays:
const boolean outmuxChannel[176][15]={
    {0,1,1,1,1,1,1,1,1,1,1,0,0,0,0}, //channel 0
    {0,1,1,1,1,1,1,1,1,1,1,1,0,0,0}, //channel 1
    {0,1,1,1,1,1,1,1,1,1,1,0,1,0,0}, //channel 2
    {0,1,1,1,1,1,1,1,1,1,1,1,1,0,0}, //channel 3
    {0,1,1,1,1,1,1,1,1,1,1,0,0,1,0}, //channel 4
    {0,1,1,1,1,1,1,1,1,1,1,1,0,1,0}, //channel 5
    {0,1,1,1,1,1,1,1,1,1,1,0,1,1,0}, //channel 6
    {0,1,1,1,1,1,1,1,1,1,1,1,1,1,0}, //channel 7
    {0,1,1,1,1,1,1,1,1,1,1,0,0,0,1}, //channel 8
    {0,1,1,1,1,1,1,1,1,1,1,1,0,0,1}, //channel 9
    {0,1,1,1,1,1,1,1,1,1,1,0,1,0,1}, //channel 10
    {0,1,1,1,1,1,1,1,1,1,1,1,1,0,1}, //channel 11
    {0,1,1,1,1,1,1,1,1,1,1,0,0,1,1}, //channel 12
    {0,1,1,1,1,1,1,1,1,1,1,1,0,1,1}, //channel 13
    {0,1,1,1,1,1,1,1,1,1,1,0,1,1,1}, //channel 14
    {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},  //channel 15

    {1,0,1,1,1,1,1,1,1,1,1,0,0,0,0}, //channel 0
    {1,0,1,1,1,1,1,1,1,1,1,1,0,0,0}, //channel 1
    {1,0,1,1,1,1,1,1,1,1,1,0,1,0,0}, //channel 2
    {1,0,1,1,1,1,1,1,1,1,1,1,1,0,0}, //channel 3
    {1,0,1,1,1,1,1,1,1,1,1,0,0,1,0}, //channel 4
    {1,0,1,1,1,1,1,1,1,1,1,1,0,1,0}, //channel 5
    {1,0,1,1,1,1,1,1,1,1,1,0,1,1,0}, //channel 6
    {1,0,1,1,1,1,1,1,1,1,1,1,1,1,0}, //channel 7
    {1,0,1,1,1,1,1,1,1,1,1,0,0,0,1}, //channel 8
    {1,0,1,1,1,1,1,1,1,1,1,1,0,0,1}, //channel 9
    {1,0,1,1,1,1,1,1,1,1,1,0,1,0,1}, //channel 10
    {1,0,1,1,1,1,1,1,1,1,1,1,1,0,1}, //channel 11
    {1,0,1,1,1,1,1,1,1,1,1,0,0,1,1}, //channel 12
    {1,0,1,1,1,1,1,1,1,1,1,1,0,1,1}, //channel 13
    {1,0,1,1,1,1,1,1,1,1,1,0,1,1,1}, //channel 14
    {1,0,1,1,1,1,1,1,1,1,1,1,1,1,1}, //channel 15

    {1,1,0,1,1,1,1,1,1,1,1,0,0,0,0}, //channel 0
    {1,1,0,1,1,1,1,1,1,1,1,1,0,0,0}, //channel 1
    {1,1,0,1,1,1,1,1,1,1,1,0,1,0,0}, //channel 2
    {1,1,0,1,1,1,1,1,1,1,1,1,1,0,0}, //channel 3
    {1,1,0,1,1,1,1,1,1,1,1,0,0,1,0}, //channel 4
    {1,1,0,1,1,1,1,1,1,1,1,1,0,1,0}, //channel 5
    {1,1,0,1,1,1,1,1,1,1,1,0,1,1,0}, //channel 6
    {1,1,0,1,1,1,1,1,1,1,1,1,1,1,0}, //channel 7
    {1,1,0,1,1,1,1,1,1,1,1,0,0,0,1}, //channel 8
    {1,1,0,1,1,1,1,1,1,1,1,1,0,0,1}, //channel 9
    {1,1,0,1,1,1,1,1,1,1,1,0,1,0,1}, //channel 10
    {1,1,0,1,1,1,1,1,1,1,1,1,1,0,1}, //channel 11
    {1,1,0,1,1,1,1,1,1,1,1,0,0,1,1}, //channel 12
    {1,1,0,1,1,1,1,1,1,1,1,1,0,1,1}, //channel 13
    {1,1,0,1,1,1,1,1,1,1,1,0,1,1,1}, //channel 14
    {1,1,0,1,1,1,1,1,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,0,1,1,1,1,1,1,1,0,0,0,0}, //channel 0
    {1,1,1,0,1,1,1,1,1,1,1,1,0,0,0}, //channel 1
    {1,1,1,0,1,1,1,1,1,1,1,0,1,0,0}, //channel 2
    {1,1,1,0,1,1,1,1,1,1,1,1,1,0,0}, //channel 3
    {1,1,1,0,1,1,1,1,1,1,1,0,0,1,0}, //channel 4
    {1,1,1,0,1,1,1,1,1,1,1,1,0,1,0}, //channel 5
    {1,1,1,0,1,1,1,1,1,1,1,0,1,1,0}, //channel 6
    {1,1,1,0,1,1,1,1,1,1,1,1,1,1,0}, //channel 7
    {1,1,1,0,1,1,1,1,1,1,1,0,0,0,1}, //channel 8
    {1,1,1,0,1,1,1,1,1,1,1,1,0,0,1}, //channel 9
    {1,1,1,0,1,1,1,1,1,1,1,0,1,0,1}, //channel 10
    {1,1,1,0,1,1,1,1,1,1,1,1,1,0,1}, //channel 11
    {1,1,1,0,1,1,1,1,1,1,1,0,0,1,1}, //channel 12
    {1,1,1,0,1,1,1,1,1,1,1,1,0,1,1}, //channel 13
    {1,1,1,0,1,1,1,1,1,1,1,0,1,1,1}, //channel 14
    {1,1,1,0,1,1,1,1,1,1,1,1,1,1,1}, //channel 15

    {1,1,1,1,0,1,1,1,1,1,1,0,0,0,0}, //channel 0
    {1,1,1,1,0,1,1,1,1,1,1,1,0,0,0}, //channel 1
    {1,1,1,1,0,1,1,1,1,1,1,0,1,0,0}, //channel 2
    {1,1,1,1,0,1,1,1,1,1,1,1,1,0,0}, //channel 3
    {1,1,1,1,0,1,1,1,1,1,1,0,0,1,0}, //channel 4
    {1,1,1,1,0,1,1,1,1,1,1,1,0,1,0}, //channel 5
    {1,1,1,1,0,1,1,1,1,1,1,0,1,1,0}, //channel 6
    {1,1,1,1,0,1,1,1,1,1,1,1,1,1,0}, //channel 7
    {1,1,1,1,0,1,1,1,1,1,1,0,0,0,1}, //channel 8
    {1,1,1,1,0,1,1,1,1,1,1,1,0,0,1}, //channel 9
    {1,1,1,1,0,1,1,1,1,1,1,0,1,0,1}, //channel 10
    {1,1,1,1,0,1,1,1,1,1,1,1,1,0,1}, //channel 11
    {1,1,1,1,0,1,1,1,1,1,1,0,0,1,1}, //channel 12
    {1,1,1,1,0,1,1,1,1,1,1,1,0,1,1}, //channel 13
    {1,1,1,1,0,1,1,1,1,1,1,0,1,1,1}, //channel 14
    {1,1,1,1,0,1,1,1,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,0,1,1,1,1,1,0,0,0,0}, //channel 0
    {1,1,1,1,1,0,1,1,1,1,1,1,0,0,0}, //channel 1
    {1,1,1,1,1,0,1,1,1,1,1,0,1,0,0}, //channel 2
    {1,1,1,1,1,0,1,1,1,1,1,1,1,0,0}, //channel 3
    {1,1,1,1,1,0,1,1,1,1,1,0,0,1,0}, //channel 4
    {1,1,1,1,1,0,1,1,1,1,1,1,0,1,0}, //channel 5
    {1,1,1,1,1,0,1,1,1,1,1,0,1,1,0}, //channel 6
    {1,1,1,1,1,0,1,1,1,1,1,1,1,1,0}, //channel 7
    {1,1,1,1,1,0,1,1,1,1,1,0,0,0,1}, //channel 8
    {1,1,1,1,1,0,1,1,1,1,1,1,0,0,1}, //channel 9
    {1,1,1,1,1,0,1,1,1,1,1,0,1,0,1}, //channel 10
    {1,1,1,1,1,0,1,1,1,1,1,1,1,0,1}, //channel 11
    {1,1,1,1,1,0,1,1,1,1,1,0,0,1,1}, //channel 12
    {1,1,1,1,1,0,1,1,1,1,1,1,0,1,1}, //channel 13
    {1,1,1,1,1,0,1,1,1,1,1,0,1,1,1}, //channel 14
    {1,1,1,1,1,0,1,1,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,1,0,1,1,1,1,0,0,0,0}, //channel 0
    {1,1,1,1,1,1,0,1,1,1,1,1,0,0,0}, //channel 1
    {1,1,1,1,1,1,0,1,1,1,1,0,1,0,0}, //channel 2
    {1,1,1,1,1,1,0,1,1,1,1,1,1,0,0}, //channel 3
    {1,1,1,1,1,1,0,1,1,1,1,0,0,1,0}, //channel 4
    {1,1,1,1,1,1,0,1,1,1,1,1,0,1,0}, //channel 5
    {1,1,1,1,1,1,0,1,1,1,1,0,1,1,0}, //channel 6
    {1,1,1,1,1,1,0,1,1,1,1,1,1,1,0}, //channel 7
    {1,1,1,1,1,1,0,1,1,1,1,0,0,0,1}, //channel 8
    {1,1,1,1,1,1,0,1,1,1,1,1,0,0,1}, //channel 9
    {1,1,1,1,1,1,0,1,1,1,1,0,1,0,1}, //channel 10
    {1,1,1,1,1,1,0,1,1,1,1,1,1,0,1}, //channel 11
    {1,1,1,1,1,1,0,1,1,1,1,0,0,1,1}, //channel 12
    {1,1,1,1,1,1,0,1,1,1,1,1,0,1,1}, //channel 13
    {1,1,1,1,1,1,0,1,1,1,1,0,1,1,1}, //channel 14
    {1,1,1,1,1,1,0,1,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,1,1,0,1,1,1,0,0,0,0}, //channel 0
    {1,1,1,1,1,1,1,0,1,1,1,1,0,0,0}, //channel 1
    {1,1,1,1,1,1,1,0,1,1,1,0,1,0,0}, //channel 2
    {1,1,1,1,1,1,1,0,1,1,1,1,1,0,0}, //channel 3
    {1,1,1,1,1,1,1,0,1,1,1,0,0,1,0}, //channel 4
    {1,1,1,1,1,1,1,0,1,1,1,1,0,1,0}, //channel 5
    {1,1,1,1,1,1,1,0,1,1,1,0,1,1,0}, //channel 6
    {1,1,1,1,1,1,1,0,1,1,1,1,1,1,0}, //channel 7
    {1,1,1,1,1,1,1,0,1,1,1,0,0,0,1}, //channel 8
    {1,1,1,1,1,1,1,0,1,1,1,1,0,0,1}, //channel 9
    {1,1,1,1,1,1,1,0,1,1,1,0,1,0,1}, //channel 10
    {1,1,1,1,1,1,1,0,1,1,1,1,1,0,1}, //channel 11
    {1,1,1,1,1,1,1,0,1,1,1,0,0,1,1}, //channel 12
    {1,1,1,1,1,1,1,0,1,1,1,1,0,1,1}, //channel 13
    {1,1,1,1,1,1,1,0,1,1,1,0,1,1,1}, //channel 14
    {1,1,1,1,1,1,1,0,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,1,1,1,0,1,1,0,0,0,0}, //channel 0
    {1,1,1,1,1,1,1,1,0,1,1,1,0,0,0}, //channel 1
    {1,1,1,1,1,1,1,1,0,1,1,0,1,0,0}, //channel 2
    {1,1,1,1,1,1,1,1,0,1,1,1,1,0,0}, //channel 3
    {1,1,1,1,1,1,1,1,0,1,1,0,0,1,0}, //channel 4
    {1,1,1,1,1,1,1,1,0,1,1,1,0,1,0}, //channel 5
    {1,1,1,1,1,1,1,1,0,1,1,0,1,1,0}, //channel 6
    {1,1,1,1,1,1,1,1,0,1,1,1,1,1,0}, //channel 7
    {1,1,1,1,1,1,1,1,0,1,1,0,0,0,1}, //channel 8
    {1,1,1,1,1,1,1,1,0,1,1,1,0,0,1}, //channel 9
    {1,1,1,1,1,1,1,1,0,1,1,0,1,0,1}, //channel 10
    {1,1,1,1,1,1,1,1,0,1,1,1,1,0,1}, //channel 11
    {1,1,1,1,1,1,1,1,0,1,1,0,0,1,1}, //channel 12
    {1,1,1,1,1,1,1,1,0,1,1,1,0,1,1}, //channel 13
    {1,1,1,1,1,1,1,1,0,1,1,0,1,1,1}, //channel 14
    {1,1,1,1,1,1,1,1,0,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,1,1,1,1,0,1,0,0,0,0}, //channel 0
    {1,1,1,1,1,1,1,1,1,0,1,1,0,0,0}, //channel 1
    {1,1,1,1,1,1,1,1,1,0,1,0,1,0,0}, //channel 2
    {1,1,1,1,1,1,1,1,1,0,1,1,1,0,0}, //channel 3
    {1,1,1,1,1,1,1,1,1,0,1,0,0,1,0}, //channel 4
    {1,1,1,1,1,1,1,1,1,0,1,1,0,1,0}, //channel 5
    {1,1,1,1,1,1,1,1,1,0,1,0,1,1,0}, //channel 6
    {1,1,1,1,1,1,1,1,1,0,1,1,1,1,0}, //channel 7
    {1,1,1,1,1,1,1,1,1,0,1,0,0,0,1}, //channel 8
    {1,1,1,1,1,1,1,1,1,0,1,1,0,0,1}, //channel 9
    {1,1,1,1,1,1,1,1,1,0,1,0,1,0,1}, //channel 10
    {1,1,1,1,1,1,1,1,1,0,1,1,1,0,1}, //channel 11
    {1,1,1,1,1,1,1,1,1,0,1,0,0,1,1}, //channel 12
    {1,1,1,1,1,1,1,1,1,0,1,1,0,1,1}, //channel 13
    {1,1,1,1,1,1,1,1,1,0,1,0,1,1,1}, //channel 14
    {1,1,1,1,1,1,1,1,1,0,1,1,1,1,1},  //channel 15

    {1,1,1,1,1,1,1,1,1,1,0,0,0,0,0}, //channel 0
    {1,1,1,1,1,1,1,1,1,1,0,1,0,0,0}, //channel 1
    {1,1,1,1,1,1,1,1,1,1,0,0,1,0,0}, //channel 2
    {1,1,1,1,1,1,1,1,1,1,0,1,1,0,0}, //channel 3
    {1,1,1,1,1,1,1,1,1,1,0,0,0,1,0}, //channel 4
    {1,1,1,1,1,1,1,1,1,1,0,1,0,1,0}, //channel 5
    {1,1,1,1,1,1,1,1,1,1,0,0,1,1,0}, //channel 6
    {1,1,1,1,1,1,1,1,1,1,0,1,1,1,0}, //channel 7
    {1,1,1,1,1,1,1,1,1,1,0,0,0,0,1}, //channel 8
    {1,1,1,1,1,1,1,1,1,1,0,1,0,0,1}, //channel 9
    {1,1,1,1,1,1,1,1,1,1,0,0,1,0,1}, //channel 10
    {1,1,1,1,1,1,1,1,1,1,0,1,1,0,1}, //channel 11
    {1,1,1,1,1,1,1,1,1,1,0,0,0,1,1}, //channel 12
    {1,1,1,1,1,1,1,1,1,1,0,1,0,1,1}, //channel 13
    {1,1,1,1,1,1,1,1,1,1,0,0,1,1,1}, //channel 14
    {1,1,1,1,1,1,1,1,1,1,0,1,1,1,1},  //channel 15
  };

const boolean inmuxChannel[96][10]={
    {0,1,1,1,1,1,0,0,0,0}, //channel 0
    {0,1,1,1,1,1,1,0,0,0}, //channel 1
    {0,1,1,1,1,1,0,1,0,0}, //channel 2
    {0,1,1,1,1,1,1,1,0,0}, //channel 3
    {0,1,1,1,1,1,0,0,1,0}, //channel 4
    {0,1,1,1,1,1,1,0,1,0}, //channel 5
    {0,1,1,1,1,1,0,1,1,0}, //channel 6
    {0,1,1,1,1,1,1,1,1,0}, //channel 7
    {0,1,1,1,1,1,0,0,0,1}, //channel 8
    {0,1,1,1,1,1,1,0,0,1}, //channel 9
    {0,1,1,1,1,1,0,1,0,1}, //channel 10
    {0,1,1,1,1,1,1,1,0,1}, //channel 11
    {0,1,1,1,1,1,0,0,1,1}, //channel 12
    {0,1,1,1,1,1,1,0,1,1}, //channel 13
    {0,1,1,1,1,1,0,1,1,1}, //channel 14
    {0,1,1,1,1,1,1,1,1,1},  //channel 15

    {1,0,1,1,1,1,0,0,0,0}, //channel 0
    {1,0,1,1,1,1,1,0,0,0}, //channel 1
    {1,0,1,1,1,1,0,1,0,0}, //channel 2
    {1,0,1,1,1,1,1,1,0,0}, //channel 3
    {1,0,1,1,1,1,0,0,1,0}, //channel 4
    {1,0,1,1,1,1,1,0,1,0}, //channel 5
    {1,0,1,1,1,1,0,1,1,0}, //channel 6
    {1,0,1,1,1,1,1,1,1,0}, //channel 7
    {1,0,1,1,1,1,0,0,0,1}, //channel 8
    {1,0,1,1,1,1,1,0,0,1}, //channel 9
    {1,0,1,1,1,1,0,1,0,1}, //channel 10
    {1,0,1,1,1,1,1,1,0,1}, //channel 11
    {1,0,1,1,1,1,0,0,1,1}, //channel 12
    {1,0,1,1,1,1,1,0,1,1}, //channel 13
    {1,0,1,1,1,1,0,1,1,1}, //channel 14
    {1,0,1,1,1,1,1,1,1,1},  //channel 15

    {1,1,0,1,1,1,0,0,0,0}, //channel 0
    {1,1,0,1,1,1,1,0,0,0}, //channel 1
    {1,1,0,1,1,1,0,1,0,0}, //channel 2
    {1,1,0,1,1,1,1,1,0,0}, //channel 3
    {1,1,0,1,1,1,0,0,1,0}, //channel 4
    {1,1,0,1,1,1,1,0,1,0}, //channel 5
    {1,1,0,1,1,1,0,1,1,0}, //channel 6
    {1,1,0,1,1,1,1,1,1,0}, //channel 7
    {1,1,0,1,1,1,0,0,0,1}, //channel 8
    {1,1,0,1,1,1,1,0,0,1}, //channel 9
    {1,1,0,1,1,1,0,1,0,1}, //channel 10
    {1,1,0,1,1,1,1,1,0,1}, //channel 11
    {1,1,0,1,1,1,0,0,1,1}, //channel 12
    {1,1,0,1,1,1,1,0,1,1}, //channel 13
    {1,1,0,1,1,1,0,1,1,1}, //channel 14
    {1,1,0,1,1,1,1,1,1,1},  //channel 15

    {1,1,1,0,1,1,0,0,0,0}, //channel 0
    {1,1,1,0,1,1,1,0,0,0}, //channel 1
    {1,1,1,0,1,1,0,1,0,0}, //channel 2
    {1,1,1,0,1,1,1,1,0,0}, //channel 3
    {1,1,1,0,1,1,0,0,1,0}, //channel 4
    {1,1,1,0,1,1,1,0,1,0}, //channel 5
    {1,1,1,0,1,1,0,1,1,0}, //channel 6
    {1,1,1,0,1,1,1,1,1,0}, //channel 7
    {1,1,1,0,1,1,0,0,0,1}, //channel 8
    {1,1,1,0,1,1,1,0,0,1}, //channel 9
    {1,1,1,0,1,1,0,1,0,1}, //channel 10
    {1,1,1,0,1,1,1,1,0,1}, //channel 11
    {1,1,1,0,1,1,0,0,1,1}, //channel 12
    {1,1,1,0,1,1,1,0,1,1}, //channel 13
    {1,1,1,0,1,1,0,1,1,1}, //channel 14
    {1,1,1,0,1,1,1,1,1,1},  //channel 15

    {1,1,1,1,0,1,0,0,0,0}, //channel 0
    {1,1,1,1,0,1,1,0,0,0}, //channel 1
    {1,1,1,1,0,1,0,1,0,0}, //channel 2
    {1,1,1,1,0,1,1,1,0,0}, //channel 3
    {1,1,1,1,0,1,0,0,1,0}, //channel 4
    {1,1,1,1,0,1,1,0,1,0}, //channel 5
    {1,1,1,1,0,1,0,1,1,0}, //channel 6
    {1,1,1,1,0,1,1,1,1,0}, //channel 7
    {1,1,1,1,0,1,0,0,0,1}, //channel 8
    {1,1,1,1,0,1,1,0,0,1}, //channel 9
    {1,1,1,1,0,1,0,1,0,1}, //channel 10
    {1,1,1,1,0,1,1,1,0,1}, //channel 11
    {1,1,1,1,0,1,0,0,1,1}, //channel 12
    {1,1,1,1,0,1,1,0,1,1}, //channel 13
    {1,1,1,1,0,1,0,1,1,1}, //channel 14
    {1,1,1,1,0,1,1,1,1,1},  //channel 15
    
    {1,1,1,1,1,0,0,0,0,0}, //channel 0
    {1,1,1,1,1,0,1,0,0,0}, //channel 1
    {1,1,1,1,1,0,0,1,0,0}, //channel 2
    {1,1,1,1,1,0,1,1,0,0}, //channel 3
    {1,1,1,1,1,0,0,0,1,0}, //channel 4
    {1,1,1,1,1,0,1,0,1,0}, //channel 5
    {1,1,1,1,1,0,0,1,1,0}, //channel 6
    {1,1,1,1,1,0,1,1,1,0}, //channel 7
    {1,1,1,1,1,0,0,0,0,1}, //channel 8
    {1,1,1,1,1,0,1,0,0,1}, //channel 9
    {1,1,1,1,1,0,0,1,0,1}, //channel 10
    {1,1,1,1,1,0,1,1,0,1}, //channel 11
    {1,1,1,1,1,0,0,0,1,1}, //channel 12
    {1,1,1,1,1,0,1,0,1,1}, //channel 13
    {1,1,1,1,1,0,0,1,1,1}, //channel 14
    {1,1,1,1,1,0,1,1,1,1}  //channel 15
};

//Other variables:
int inByte = 0;
int valor = 0;               
int calibra[96][176];         
int minsensor=100;         


void setup(){
  
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 
  pinMode(eninMux1, OUTPUT);
  pinMode(eninMux2, OUTPUT);
  pinMode(eninMux3, OUTPUT);
  pinMode(eninMux4, OUTPUT);
  pinMode(eninMux5, OUTPUT);
  pinMode(eninMux6, OUTPUT);
  
  pinMode(w0, OUTPUT); 
  pinMode(w1, OUTPUT); 
  pinMode(w2, OUTPUT); 
  pinMode(w3, OUTPUT); 
  pinMode(enoutMux1, OUTPUT);
  pinMode(enoutMux2, OUTPUT);
  pinMode(enoutMux3, OUTPUT);
  pinMode(enoutMux4, OUTPUT);
  pinMode(enoutMux5, OUTPUT);
  pinMode(enoutMux6, OUTPUT);
  pinMode(enoutMux7, OUTPUT);
  pinMode(enoutMux8, OUTPUT);
  pinMode(enoutMux9, OUTPUT);
  pinMode(enoutMux10, OUTPUT);
  pinMode(enoutMux11, OUTPUT);
  
  pinMode(OUT_pin, OUTPUT);
  pinMode(SIG_pin, INPUT);
  //analogReadResolution(8);

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  
  digitalWrite(w0, LOW);
  digitalWrite(w1, LOW);
  digitalWrite(w2, LOW);
  digitalWrite(w3, LOW);
  
  digitalWrite(OUT_pin, HIGH);
  
  Serial.begin(2000000);
  
  Serial.println("\n\Calibrating...\n");
  
  // Calibration  
    for(byte j = 0; j < 176; j ++){ 
      writeMux(j);
      for(byte i = 0; i < 96; i ++)
        calibra[i][j] =  readMux(i);
    }
  
  //Print averages
  for(byte j = 0; j < 176; j ++){ 
    writeMux(j);
    for(byte i = 0; i < 96; i ++){
     if(calibra[i][j] < minsensor)
     minsensor = calibra[i][j];
      Serial.print(calibra[i][j]);
      Serial.print("\t");
    }
  Serial.println(); 
  }
  
  Serial.println();
  Serial.print("Minimum Value: ");
  Serial.println(minsensor);
  Serial.println();
  
  establishContact();
}


void loop(){
  if (Serial.available() > 0){
    inByte = Serial.read();
    
    if(inByte == 'A'){
    
      for(int j = 0; j < 176; j++){ 
        writeMux(j);
        
        for(int i = 0; i < 96; i++){
            
          valor = readMux(i);
          valor = (valor-calibra[i][j]);
          
          if(valor < 5)
            valor = 0;
          
          Serial.write(valor);
        } 
      }
    }
  }
}

int readMux(byte channel){
  
  byte control1Pin[] = {eninMux1, eninMux2, eninMux3, eninMux4, eninMux5, eninMux6, s0, s1, s2, s3};
  for(int i = 0; i < 10; i ++){
    digitalWrite(control1Pin[i], inmuxChannel[channel][i]); 
  }
  int val = analogRead(SIG_pin);
  return val;
}

void writeMux(byte channel){
  
  byte control2Pin[] = {enoutMux1, enoutMux2, enoutMux3, enoutMux4, enoutMux5, enoutMux6, enoutMux7, enoutMux8, enoutMux9, enoutMux10, enoutMux11, w0, w1, w2, w3};
  for(byte i = 0; i < 15; i ++){
    digitalWrite(control2Pin[i], outmuxChannel[channel][i]);
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.print('A');   
    delay(1000);
  }
}
Can anyone help me on this?
Thank you all
klausfelix
Posts: 1
Joined: Mon Nov 15, 2021 4:56 pm

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by klausfelix »

One resistor to ground before the multiplexer, the series diode should not be needed.

The walue of this resistor should be adjusted to be approximately equal to the velostat layer resistance for one crossing when half depressed.

If you dont have a pull down resistor the the sense line becomes "floating" then the corresponding row/column crossing is not depressed.

So the state is essentially, undefined, dependent on input impedance of the multiplexer inputs.

This floating state can very well be the cause of the memory effect you see.
robertryan
Posts: 1
Joined: Fri Dec 03, 2021 6:05 pm

Re: Crosstalk and sample frequency issues on a pressure sensor matrix

Post by robertryan »

One resistor to ground before the multiplexer, the series diode should not be needed.

The walue of this resistor should be adjusted to be approximately equal to the velostat layer resistance for one crossing when half depressed.

If you dont have a pull down resistor the the sense line becomes "floating" then the corresponding row/column crossing is not depressed.

So the state is essentially, undefined, dependent on input impedance of the multiplexer inputs.

This floating state can very well be the cause of the memory effect you see.
Post Reply

Return to “General discussion”