Dummy load Digitally controlled by Arduino 328 - Page 1
Forum section: electronics / projects

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 02:44:12 pm
content: Hi guysi 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 perfectelse 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 itDescription of the LCDBV means Bus Voltage in voltsmA means current flowing through the resistor acting as loadThe Number 2 ( range 0,1,2,3) stand for Multiplier that it is it multiplies the rotary encoder valuesThe code RunningCode:[/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 readingsunsigned long old_millis = 0;// rotatary variablesRotaryEncoder 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;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 eventint buttonVal = 0; // value read from buttonlong btnDnTime; // time the button was pressed down//Delayint 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 0int 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 backlightlcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);lcd.setBacklight(LED_ON);lcd.clear();lcd.home();// Print our characters on the LCDlcd.backlight(); //Backlight ON if under program controldelay(500);ina219.begin();delay(500);dac.begin(0x62);pinMode(2, INPUT_PULLUP);}// END Setupvoid 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");//DAClcd.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 wavecounter =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;}//reverseif ((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 counterif (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]

author: robrenz
author_rank: Super Contributor
timestamp: August 21, 2013, 03:10:14 pm
content: 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.

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 03:22:55 pm
content: Quote from: robrenz on August 21, 2013, 03:10:14 pmThanks Robrenz, but i have tried to resize it but it losses its quality as it was more than thisregardsshailesh

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 03:53:11 pm
content: Quote from: robrenz on August 21, 2013, 03:46:48 pmya it do look, i think its program am using , i have used paint, what program are you using,thanksshailesh

author: robrenz
author_rank: Super Contributor
timestamp: August 21, 2013, 03:54:56 pm
content: I am just using the picture editor of Microsoft Office.

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 04:04:29 pm
content: Quote from: robrenz on August 21, 2013, 03:54:56 pmAlready replaced the Picture with the one you have compressed,thanks n regardsshailesh

author: Unknown
author_rank: Unknown
timestamp: August 21, 2013, 04:15:22 pm
content: The code will look much better and will be easier to read if you put it between code tags:Code:like thisYou can also use the button labeled with a number sign: #

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 04:44:36 pm
content: Quote from: alm on August 21, 2013, 04:15:22 pmThanks ALM already done it

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 21, 2013, 10:34:38 pm
content: 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 viewsregardsshailesh

author: jaxbird
author_rank: Frequent Contributor
timestamp: August 22, 2013, 10:24:53 am
content: Very NiceIt'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?

author: PA0PBZ
author_rank: Super Contributor
timestamp: August 22, 2013, 10:53:54 am
content: That's not a Dummy load, it is an Intelligent load

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 22, 2013, 01:12:30 pm
content: Quote from: jaxbird on August 22, 2013, 10:24:53 amThanks 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

author: shailesh3t
author_rank: Regular Contributor
timestamp: August 22, 2013, 01:14:17 pm
content: Quote from: PA0PBZ on August 22, 2013, 10:53:54 amThanks PAOPBZ, else what are you designing , i mean your are interested in which designs