Author Topic: Dummy load Digitally controlled by Arduino 328  (Read 10723 times)

0 Members and 3 Guests are viewing this topic.

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Dummy load Digitally controlled by Arduino 328
« on: August 21, 2013, 02:44:12 pm »
Hi guys
i have designed a dummy load based on DAVE Jones, MJlorton and Jjoster  Dummyload and have used libraries from JJoster for the rotary encoder and Libraries from ADAfruit for DAC and the INA 219.
 MCP 4725 is the DAC to set the voltage ( 0 - 4096 steps which corresponds to 0 - 5000 mV )  on the LM324 to control the mosfet  and finally i am  using arduino 328 to control the DAC and  INA 219 ( current , voltage, power reading @ 12bit) and an IIC lcd to  display the settings and readings of a rotary encoder to set the current.
am still writing program and its not that perfect
else am not an expert in programming n electronics am still learning n most of time i use libraries made by some experts, like D jones, JJoster,Mjlorton n ...
tonight or tomorrow am going to post a video of it
 
Description of the LCD
BV means Bus Voltage in volts
mA means current flowing through the resistor acting as load
The Number 2 ( range 0,1,2,3) stand for Multiplier that it is it multiplies the rotary encoder values

The code Running

Code: [Select]
[/code
//version 1

#include <RotaryEncoder.h>


// A0-A1-A2 are grounded so I2C Address is 0x38 

/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
#include <Adafruit_INA219.h>
#include <Adafruit_MCP4725.h>

Adafruit_INA219 ina219;
Adafruit_MCP4725 dac;

unsigned int constant_millis = 500;              //TC77 delay between readings
unsigned long old_millis = 0;

// rotatary variables
RotaryEncoder encoder(A0,A2,5,6,3000);
//(int ENC_A, int ENC_B, int multiplier, int stepSize, int pauseLength)

int val = 0;
int cnt  = 0;
char s[21];
int remainder;

#define debounce 20 // ms debounce period to prevent flickering when pressing or releasing the button
#define holdTime 700 // ms hold period: how long to wait for press+hold event
int buttonVal = 0; // value read from button
long btnDnTime; // time the button was pressed down



//Delay
int Dcount = 0;



//Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move original LiquidCrystal library elsewhere, copy this in it's place

/*-----( Declare Constants )-----*/
#define I2C_ADDR    0x20  // Define I2C Address for the PCF8574T
//---(Following are the PCF8574 pin assignments to LCD connections )----
// This are different than earlier/different I2C LCD displays
#define BACKLIGHT_PIN  3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

#define  LED_OFF  1
#define  LED_ON  0



int test = 0;
//float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
//  float loadvoltage = 0;
//float power = 0;

/*-----( Declare objects )-----*/ 
LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
 //Serial.begin(57600);
  lcd.begin (16,2);  // initialize the lcd
 
// Switch on the backlight
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(LED_ON);
  lcd.clear();
   
 lcd.home();
 
// Print our characters on the LCD
  lcd.backlight();  //Backlight ON if under program control
 
 
 
  delay(500);
 ina219.begin();
 delay(500);
dac.begin(0x62);

pinMode(2, INPUT_PULLUP);


}// END Setup


void WriteLCD1(void)
{
   lcd.setCursor(0,0);
  lcd.print(busvoltage);
 lcd.setCursor(5,0);
  lcd.print("BV");
 
     
 lcd.setCursor(8,0);
lcd.print(current_mA);
 lcd.setCursor(14,0);
  lcd.print("mA");
 
 
  //DAC
  lcd.setCursor(7,1);
  sprintf(s,"%2d",val/1);
 lcd.print(s);
  lcd.print('.');
  lcd.setCursor(12,1);
  lcd.print(" DAC");
 
 
// lcd.setCursor(0,1);
 // lcd.print(loadvoltage);
 //lcd.setCursor(4,1);
 // lcd.print("LDV");
lcd.setCursor(0,1);
lcd.print(cnt);
 
 
 //lcd.setCursor(1,1);
//lcd.print(power);

}


void Updatedac(void)
{
uint32_t counter;
    // Run through the full 12-bit scale for a triangle wave
    counter =val;
   
      dac.setVoltage(counter, false);
}


void CurrentSense(void)
{
 

  //shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  //loadvoltage = busvoltage + (shuntvoltage / 1000);
 
 // power= busvoltage*current_mA;
 
 
 // Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
 // Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  //Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  //Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  //Serial.println("");

 
}


void loop()   /*----( LOOP: RUNS OVER AND OVER AGAIN )----*/

  {
  int enc = encoder.readEncoder();
  int changevalue = 1;
  if(enc != 0) {
    val = val + (enc);
    val = min(val,4095);
    val = max(val,0);
     
     
       if ((cnt == 1) && ( enc == 1)) {
        val = val + 1;
       }
       
       
       if ((cnt == 2) && ( enc == 1)) {
        val = val + 10;
       }
       
       if ((cnt == 3) && ( enc == 1)) {
        val = val + 100;
       }
       
       
       //reverse
       
       if ((cnt == 1) && ( enc <= 0)) {
        val = val - 1;
       }
       
         
       if ((cnt == 2) && ( enc <= 0)) {
        val = val - 10;
       }
         
       if ((cnt == 3) && ( enc <= 0)) {
        val = val - 100;
       }
       
       if (val >= 4096) {
         val = 4095;
       }
       if (val <= 0) {
         val = 0;
       }
       
       
      Updatedac();
  }
   
 Dcount++;
   
   int buttonVal = digitalRead(2);
 
 
 if ((millis() - old_millis) > constant_millis) {
WriteLCD1();
old_millis = millis();
}
 
 
 
if (Dcount>4000)         
    {
      CurrentSense();
     
    Dcount=0;  //reset the counter
       
   
    if (buttonVal == LOW && (millis() - btnDnTime) > long(holdTime))
{

btnDnTime = millis();


}
  }
 
  if (buttonVal == HIGH && (millis() - btnDnTime) > long(holdTime))
{
 cnt++;
btnDnTime = millis();


if (cnt >= 4) {
  cnt = 0;
}



}
 


} // END Loop


]
« Last Edit: August 21, 2013, 10:49:44 pm by shailesh3t »
 

Offline robrenz

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
  • Real Machinist, Wannabe EE
Re: Dummy load Digitally controlled by Arduino 328
« Reply #1 on: August 21, 2013, 03:10:14 pm »
Very nice!

Your pictures will much nicer to view if you resize them to 1024 by 768 maximum. Those huge pictures are a pain to view.

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #2 on: August 21, 2013, 03:22:55 pm »
Very nice!

Your pictures will much nicer to view if you resize them to 1024 by 768 maximum. Those huge pictures are a pain to view.
Thanks Robrenz, but i  have tried to resize it but it losses its quality as it was more than this
regards
shailesh
 

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #3 on: August 21, 2013, 03:53:11 pm »
Looks fine to me at 1024 x 576  also saves space on Dave's server :-+

ya it do look, i think its program am using , i have used paint, what program are you using,
thanks
shailesh
 

Offline robrenz

  • Super Contributor
  • ***
  • Posts: 3035
  • Country: us
  • Real Machinist, Wannabe EE
Re: Dummy load Digitally controlled by Arduino 328
« Reply #4 on: August 21, 2013, 03:54:56 pm »
I am just using the picture editor of Microsoft Office.

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #5 on: August 21, 2013, 04:04:29 pm »
I am just using the picture editor of Microsoft Office.
Already replaced the Picture with the one you have compressed,
thanks n regards
shailesh
 

alm

  • Guest
Re: Dummy load Digitally controlled by Arduino 328
« Reply #6 on: August 21, 2013, 04:15:22 pm »
The code will look much better and will be easier to read if you put it between code tags:
Code: [Select]
like this
You can also use the button labeled with a number sign: #
 

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #7 on: August 21, 2013, 04:44:36 pm »
The code will look much better and will be easier to read if you put it between code tags:
Code: [Select]
like this
You can also use the button labeled with a number sign: #

Thanks ALM already done it
 

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #8 on: August 21, 2013, 10:34:38 pm »
I have attached a link for the Video on you tube,

its not complete , its has been done to 80 % but still some minor improvement is to be done,
post your comments and views
regards
shailesh
« Last Edit: August 21, 2013, 10:36:16 pm by shailesh3t »
 

Offline jaxbird

  • Frequent Contributor
  • **
  • Posts: 778
  • Country: 00
Re: Dummy load Digitally controlled by Arduino 328
« Reply #9 on: August 22, 2013, 10:24:53 am »
Very Nice  :-+

It's a nice idea to be able to change the encoder sensitivity by pressing it. I did it slightly different on mine, since I don't have a push button in it, I instead implemented acceleration, but it's a bit tricky to get right.

Can you control the load as it is now? Or just reading the values?

Analog Discovery Projects: http://www.thestuffmade.com
Youtube random project videos: https://www.youtube.com/user/TheStuffMade
 

Offline PA0PBZ

  • Super Contributor
  • ***
  • Posts: 5215
  • Country: nl
Re: Dummy load Digitally controlled by Arduino 328
« Reply #10 on: August 22, 2013, 10:53:54 am »
That's not a Dummy load, it is an Intelligent load  :-+
Keyboard error: Press F1 to continue.
 

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #11 on: August 22, 2013, 01:12:30 pm »
Very Nice  :-+

It's a nice idea to be able to change the encoder sensitivity by pressing it. I did it slightly different on mine, since I don't have a push button in it, I instead implemented acceleration, but it's a bit tricky to get right.

Can you control the load as it is now? Or just reading the values?

Thanks JAxbird, else i  can control the current going through the load but in some range of current there is a little noise i have not yet got time to see the problem exactly, in fact it does include acceleration but  i think due to the fact  the processor is busy doing other things its cannot do the acceleration , if i eliminate the DAC and ADC function the acceleration mode works that why i have implement the push button method
« Last Edit: August 22, 2013, 01:22:24 pm by shailesh3t »
 

Offline shailesh3tTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: mu
Re: Dummy load Digitally controlled by Arduino 328
« Reply #12 on: August 22, 2013, 01:14:17 pm »
That's not a Dummy load, it is an Intelligent load  :-+
Thanks PAOPBZ, else what are you designing , i mean your are interested in which designs
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf