Code guidance for programmable power supply

Hello all,

I have been searching the forums to try and find some answers but I am kinda stuck at this point. I am trying to create a programmable power supply similar to this one: http://youtu.be/zUTZ4zQ2HoA

Now I am finishing up my computer and electronics enginerring associate program, so the hardware setup is pretty much complete. However I am very lacking in my programming skills, so if anyone who has tackled a project such as this before could provide some guidance, I would be eternally grateful! A few main points I need clarification on:

  • I need to know what would be a good initial setup to ensure the power supply output is always set to 0V when I start it up
  • What would be the best setup to scan the keypad to set the voltage (note I am using 10 individual push buttons not an existing keypad, so I need to manually setup the key scan)
  • How to provide output to the DAC while also displaying the input value on the LCD

I should be able to figure out the exact code, but I just have no idea where to even get started :\

Thanks for all of your assistance!

First, be carefull when building powersupplies... Second, be carefull .... (ok, you got the message ;)

I need to know what would be a good initial setup to ensure the power supply output is always set to 0V when I start it up

Use a relay to switch the output. This relay is default OFF . At the press of a (momentary on) button the relay goes to ON and keeps itself in an ON position by providing 5V to itself. This same relay can be used to switch the output OFF with a second (momentary off) button.

What would be the best setup to scan the keypad to set the voltage (note I am using 10 individual push buttons not an existing keypad, so I need to manually setup the key scan)

What is the range that can be set? Accuracy? f..i. if you use a potmeter and uses 200 steps of the 1024 available you could set 0..10 volt in steps of 0.05 Volt in theory.

ANother option is using an encoder wheel, every pulse adds/subtracts 0.05 volt. As a rotary encoder allways start at 0 it might also solve point 1. You can easily constrain the rotary encoder to allmost any range

If you still want to use a keypad, use a matrix 3x4 to minimize pinusage.

How to provide output to the DAC while also displaying the input value on the LCD

Look at the blink without delay example in the reference/tutorial section Also look at interrupts for the rotary encoder and analog in

simplified snippet of code (not tested or compiled, all disclaimers apply).

volatile unsigned int rotary = 0;

void setup()
{
  attachInterrupt(0, IRQ, RISING);
}

void IRQ()
{
  rotary++;
}

void loop()
{
  // GET SETTING
  rotary = constrain(rotary, 0, 10000);
  float voltage = rotary / 100.0;      // 0..10 V in steps of 0.01 

  // DISPLAY
  lcd.gotoxy(0,0);  // or something equivalent
  lcd.print(voltage, 2); // 2 decimals

  // DO ADC
  doADC(rotary);  
}

void doADC(int r)
{
  // to be elaborated
}

this should get your started

Hmm... I didn't even thing of a rotary for the input, but you would be right in the sense that it would simply things quite a bit. My only concern would be that I am trying for a range of 0V - 24V, so 0.05 per step would result in 480 required turns to get to the max voltage, which I can't visualize now if that would be excessive...

However this is a great start that I think I can start to build off of! I will begin posting my progress to show how things are going and ask for additional assistance if need be. Thanks for the help! :grin:

robtillaart:

What would be the best setup to scan the keypad to set the voltage (note I am using 10 individual push buttons not an existing keypad, so I need to manually setup the key scan)

What is the range that can be set? Accuracy? f..i. if you use a potmeter and uses 200 steps of the 1024 available you could set 0..10 volt in steps of 0.05 Volt in theory.

ANother option is using an encoder wheel, every pulse adds/subtracts 0.05 volt. As a rotary encoder allways start at 0 it might also solve point 1. You can easily constrain the rotary encoder to allmost any range

If you still want to use a keypad, use a matrix 3x4 to minimize pinusage.

Okay, upon further consideration I think I will want to stick with my original plan of 10-input buttons to select a voltage. The way I want it to work is that the first number entered would be the "tens", the 2nd number as the "ones" and the third as the "tenths" of a numerical value. For example, pressing "1" then "5" then "5" would give 15.5V output. So resolution wise, I would like to be able to have voltages from 00.0 to 24.0V (or slightly under 24V as there is voltage loss in my transistor setup) How would I scan then save these inputs and turn it into a digital output? When displaying the input, would I have the values displayed on the LCD as the user input them or wait until all of the inputs are entered before displaying, then sending the output to the DAC portion of my power supply?

I apologize for being so terribly lost with this stuff... I have the hardware setup down, its the programming part that will be the death of me!

Assuming every digit has an IO pin. You need a counter that counts the number of keys pressed. If there are 3, and the number is valid you change the voltage.

partial code, to get an idea

void loop()
{
  int v = newVoltage();
  if (v >=0) setVoltage(v);  // v is in 1/10's of volts ...
}

int newVoltage()
{
  static int count= 0;
  static int v = 0;
  int rv = -1;

  for (int i=0; i<10; i++)
  {
    if (digitalRead(PIN[i]) == LOW)    // assuming you have a pin for every button define in the array PIN...
    {
      v = v *10 + i; 
      count++;
      if (count == 3) // 3 digits collected
      {
        if (v <= 240) // and they are a valid voltage
        {
          rv = v;
        }
        // prepare for new voltage input
        count = 0;
        v = 0;
      }
      return rv;
    }
  }
  return rv;
}

Very nice, this is extremely helpful, thank you!

If you have a 3x4 matrix keypad, you can add a series of resistors to each buttons row and column creating a 1 pin analog keypad. There is a nice instructable here http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/ . This will allow you to cut down on the pins used and also comes with code for the arduino I believe.