Pages: [1]   Go Down
Author Topic: Using Arduino Uno for voltammetry  (Read 427 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,

I'm fairly new to Arduino, so forgive any ignorance.

I'm working on a project where I need specific DC voltages ranging from [0, 1] in a 5mV interval.  I've gotten this setup with generating a PWM signal with the corresponding voltages duty cycle and then using a low-pass filter to generate the DC value from the PWM.  The problem I'm hitting is that it doesn't generate every value I need, i.e. it skips some values.  For example, it will output 1v, .995v, and then jump to .975v instead of outputting .990v.  I'm starting to think that it's just because of the rounding in the desired voltage -> duty cycle percentage conversion and maybe it's not possible to get all the values I need on this board.  Any help/insight that you guys could provide would be much appreciated!

Here's the sketch I've been using:

Code:
int PWM_out_pin = 11; // Must be one of 3, 5, 6, 9, 10, or 11
double Veff = 0; //The DC voltage wanted at the output pin
double stepSize = .005;
void setup() {
  Serial.begin(9600);
  pinMode(PWM_out_pin, OUTPUT);
}

void loop() {
long double PWM_out_level;

for (Veff = 1; Veff >= 0; Veff = Veff - stepSize)
{
  PWM_out_level = (255/5)*Veff; // Code logic to set output level
  analogWrite( PWM_out_pin, PWM_out_level); // Write the desired voltage to the output pin
  delay(5000); // Hold the current voltage for 5 seconds
  Serial.println(Veff, 4);
}
}
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4554
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Think about it: You're only using 51 different values in the analogWrite() function (255/5 is 51). You're never going to get the values you want that way.

Try setting up a resistor divider on the output of your filter to divide by five. That way you can use the full output range (0 to 255).

Next, go down from 255 to 0 in steps of 1, look at the output voltages. That's the best you can do with the Arduino PWM output. Whether it's good enough or not is up to you.

Logged

No, I don't answer questions sent in private messages...

Washington
Offline Offline
God Member
*****
Karma: 30
Posts: 780
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are only 255 different steps meaning there is only 19.6mV of resolution.

The only way to get more resolution is to either rapidly switch between two PWM duty cycles or use feedback from the ADC to set the duty cycle.

I have made voltage regulators with some pass transistors and the latter method and could achieve 10mv precision over a wide load level.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For that sort of precision you should be looking at something like the MCP4821

It is controlled by SPI, and outputs a voltage at 12-bit resolution.  That's either between 0 and 2047.5mv at 0.5mV steps, or between 0 and 4095mV at 1mV steps depending on settings.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 30
Posts: 2246
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Adafruit has an MCP4725 (I2C, 12bit) breakout for $5.
Logged

0
Offline Offline
Shannon Member
****
Karma: 161
Posts: 10442
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you set timer1 to 10 bit mode you'll have 1024 PWM levels available to pins 9 and 10 (it goes up to 16 bits,
but that could make the cycle time very long.  You will need to drive the timer1 registers directly to do this,
try searching for "TCCR1A" for posts about this.

There is also a library for more advanced use of timers I believe, it might help.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: