iorodeo / potentiostat

Rodeostat design files, software and firmware
https://blog.iorodeo.com/rodeostat-product-guide/
Creative Commons Attribution 4.0 International
32 stars 12 forks source link

Shifted 100Hz Sinusoid and Sample Rate Problem #22

Closed vincent-accion closed 1 year ago

vincent-accion commented 1 year ago

Hello, I have a problem when I try to make a sinusoid with a 20ms period (or 50Hz) with a 2V amplitude. It works but instead of behind centered on 0, it is centered on -2V. How to correct this problem ? Using 'shift' doesn't do anything, and when using 'offset' it just does a flat voltage at the offset value.

Furthermore, I have an issue understanding sample rate. Is the sample rate simply the number of measurements every second and is just used to make the graph ? And no matter the sample rate the sinusoid follow its parameters ? Or does it give an output voltage according to the sample rate ? And thus the sample rate is critical to make the system work correctly ? If the second explanation is correct, then I must tune the sample rate to match the period I want to set right ? I have get it to work by putting 5 sample per period (changing the sample_rate to keep this rate for every period I set) but I need to understand it.

Thank you for your response

iorodeo commented 1 year ago

The sample rate is simply the number of measurements per seconds which are sent back to the host pc. The output waveform generated using an outscan rate of 5kHz which is set using a hardware Timer on the microcontroller.

The sample rate you use is still quite important though as you will want to have a high enough sample rate to get sufficient measurements per cycle of your sinusoid. The maximum sample rate for the Rodeostat is 1000Hz when using the Python API and 200Hz when using the web app. For this application I would suggest using the Python API with a sample rate of 1000Hz as this will at least give you 20 points per waveform. With the webapp and a sample rate of 200Hz you will only get 5 points per cycle which isn't a lot.

Regarding the parameters for the sinusoidal test.

The "shift" parameter is a unit-less phase shift parameter. It is used to specify the phase shift for the sinusoid. It takes values in the range of 0 to 1. For a sinusoid the phase shift in degrees will be 360 times the value of shift parameter (360 x shift). So if shift=0 you get a sinewave (0 degree phase shift) , if shift=0.25 you get a cosine (90 degree phase shift), etc. This parameter won't have any effect of the offset of the waveform.

The "offset" parameter sets the offset of the waveform from zero. This is essentially just a voltage which is added to the sinusoidal waveform. When offset=0 the sinusoid will be centered on 0V. When the offset=1 the sinusoid will be centered on 1V, etc.

You can find a description of the parameters for the sinusoidal test here https://iorodeo.github.io/iorodeo-potentiostat-docs-build/tests.html#sinusoidal-voltammetry

I would start by running some examples using the 50k dummy cell which comes with the Rodeostat. The following Python script will run a 50Hz sinusoid with a 2V amplitude. The sample rate is 1000Hz and the waveform is centered on 0V.

from potentiostat import Potentiostat
import sys
import matplotlib.pyplot as plt

port = '/dev/ttyACM0'
dev = Potentiostat(port)
dev.set_curr_range('100uA')
dev.set_sample_rate(1000.0)

name = 'sinusoid'
param = {
        'quietValue' : 0.0,
        'quietTime'  : 100,
        'amplitude'  : 2.0,
        'offset'     : 0.0,
        'period'     : 20,
        'numCycles'  : 10,
        'shift'      : 0.0,
        }

dev.set_param(name,param)
t,volt,curr = dev.run_test(name,display='pbar')

fig, ax = plt.subplots(2,1)
ax[0].plot(t,volt)
ax[0].set_ylabel('(V)')
ax[0].grid(True)
ax[1].plot(t,curr)
ax[1].set_ylabel('(uA)')
ax[1].set_xlabel('t (sec)')
ax[1].grid(True)
plt.show()
vincent-accion commented 1 year ago

Thank you so much ! And for simple volateg input, not cyclic voltammetry, the current range isn't important right? It is only important when you do current measurements isn't it ?

Le jeu. 15 juin 2023, 18:26, IO Rodeo @.***> a écrit :

The sample rate is simply the number of measurements per seconds which are sent back to the host pc. The output waveform generated using an outscan rate of 5kHz which is set using a hardware Timer on the microcontroller.

The sample rate you use is still quite important though as you will want to have a high enough sample rate to get sufficient measurements per cycle of your sinusoid. The maximum sample rate for the Rodeostat is 1000Hz when using the Python API and 200Hz when using the web app. For this application I would suggest using the Python API with a sample rate of 1000Hz as this will at least give you 20 points per waveform. With the webapp and a sample rate of 200Hz you will only get 5 points per cycle which isn't a lot.

Regarding the parameters for the sinusoidal test.

The "shift" parameter is a unit-less phase shift parameter. It is used to specify the phase shift for the sinusoid. It takes values in the range of 0 to 1. For a sinusoid the phase shift in degrees will be 360 times the value of shift parameter (360 x shift). So if shift=0 you get a sinewave (0 degree phase shift) , if shift=0.25 you get a cosine (90 degree phase shift), etc. This parameter won't have any effect of the offset of the waveform.

The "offset" parameter sets the offset of the waveform from zero. This is essentially just a voltage which is added to the sinusoidal waveform. When offset=0 the sinusoid will be centered on 0V. When the offset=1 the sinusoid will be centered on 1V, etc.

You can find a description of the parameters for the sinusoidal test here https://iorodeo.github.io/iorodeo-potentiostat-docs-build/tests.html#sinusoidal-voltammetry

I would start by running some examples using the 50k dummy cell which comes with the Rodeostat. The following Python script will run a 50Hz sinusoid with a 2V amplitude. The sample rate is 1000Hz and the waveform is centered on 0V.

from potentiostat import Potentiostatimport sysimport matplotlib.pyplot as plt port = '/dev/ttyACM0'dev = Potentiostat(port)dev.set_curr_range('100uA')dev.set_sample_rate(1000.0) name = 'sinusoid'param = { 'quietValue' : 0.0, 'quietTime' : 100, 'amplitude' : 2.0, 'offset' : 0.0, 'period' : 20, 'numCycles' : 10, 'shift' : 0.0, } dev.set_param(name,param)t,volt,curr = dev.run_test(name,display='pbar') fig, ax = plt.subplots(2,1)ax[0].plot(t,volt)ax[0].set_ylabel('(V)')ax[0].grid(True)ax[1].plot(t,curr)ax[1].set_ylabel('(uA)')ax[1].set_xlabel('t (sec)')ax[1].grid(True)plt.show()

— Reply to this email directly, view it on GitHub https://github.com/iorodeo/potentiostat/issues/22#issuecomment-1593377219, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATQ6LWYHLIKJUD4N3HMZWJDXLMZVDANCNFSM6AAAAAAZGDZ43Y . You are receiving this because you authored the thread.Message ID: @.***>

iorodeo commented 1 year ago

The current range is important whenever you are a test which involves measuring current. If current goes outside of the selected current range the measurement will saturate.

The device also has some intrinsic current limitations in that it can only source and sink so much current. I would recommend keeping the current with in ±10mA.

vincent-accion commented 1 year ago

I understand way better now thank you ! There is one last question I would like to ask you: as I said before for my research I electrocute bacteria and I need an AC current with a controllable amplitude and frequency. I made a script that gives me a sinusoid that should be at 100Hz with a amplitude of 2V but when I check with an oscilloscope the frequency is right but the amplitude isn't. I have tried with 10 frequencies and I always have the same problem, the frequency is right, I can see the sinusoid well, but the amplitude peak-peak isn't correct. I have discussed it with a colleague and since it's a potensiostat, he told me that it measures the difference between the different electrodes's potential and that even if I do a constant or sinusoid volatammetry (without reading current just an input of voltage into the medium) I need to set the ref electrode into a buffer otherwise the way the amplitude is measured might be off. Do you have a solution for this amplitude problem ? Thank you for your time

°°°°°°° ° ° ° ° ° Vincent ACCIÓN https://vincentaccion.xyz https://vincentaccion.xyz/

Le dim. 18 juin 2023 à 01:06, IO Rodeo @.***> a écrit :

The current range is important whenever you are a test which involves measuring current. If current goes outside of the selected current range the measurement will saturate.

The device also has some intrinsic current limitations in that it can only source and sink so much current. I would recommend keeping the current with in ±10mA.

— Reply to this email directly, view it on GitHub https://github.com/iorodeo/potentiostat/issues/22#issuecomment-1595883996, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATQ6LW2IETQ4MOFP3IWAKH3XLYZ6TANCNFSM6AAAAAAZGDZ43Y . You are receiving this because you authored the thread.Message ID: @.***>

iorodeo commented 1 year ago

Yes the Rodeostat is a potentiostat. It uses feedback to control the voltage between the working and reference electrodes using the counter electrode as an actuator. When doing this it is said to be operating in closed-loop. However, there is an easy solution for your application. You can operate the device in open-loop by connecting the reference and counter electrode outputs together. This will essentially remove the potentiostat's feedback loop. The reference and counter electrode will now always be at the same potential. You now have a two electrode device with working electrode and a combined "counter/reference" electrode. Now when you operate the device will just directly set the potential between the working and combined "counter/reference" electrode in an open-loop fashing without feedback control.

vincent-accion commented 1 year ago

Thank you very much you help us a lot !

Le jeu. 22 juin 2023, 06:08, IO Rodeo @.***> a écrit :

Yes the Rodeostat is a potentiostat. It uses feedback to control the voltage between the working and reference electrodes using the counter electrode as an actuator. When doing this it is said to be operating in closed-loop. However, there is an easy solution for your application. You can operate the device in open-loop by connecting the reference and counter electrode outputs together. This will essentially remove the potentiostat's feedback loop. The reference and counter electrode will now always be at the same potential. You now have a two electrode device with working electrode and a combined "counter/reference" electrode. Now when you operate the device will just directly set the potential between the working and combined "counter/reference" electrode in an open-loop fashing without feedback control.

— Reply to this email directly, view it on GitHub https://github.com/iorodeo/potentiostat/issues/22#issuecomment-1601984016, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATQ6LWZCD3DX6HX2CBZALSDXMPAMTANCNFSM6AAAAAAZGDZ43Y . You are receiving this because you authored the thread.Message ID: @.***>