Show Posts
Pages: [1]
1  Using Arduino / General Electronics / Using Arduino Uno for voltammetry on: January 18, 2013, 03:01:41 pm
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);
}
}
Pages: [1]