Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Wire.h"
- #include "SPI.h"
- #include "Adafruit_MCP4725.h" // DAC library
- #include "Adafruit_INA219.h" // INA219 current sensor library
- // Declare a current sensor object.
- Adafruit_INA219 ina219; // Commands like ina219.getCurrent_mA() will read the current.
- // Declare our voltage supply objects.
- Adafruit_MCP4725 dac_v_ds;
- //HERE DECLARE A SECOND DAC OBJECT TO BE USED TO SET GATE VOLTAGE (e.g. DAC_V_G)
- Adafruit_MCP4725 dac_v_g ;
- //
- #define DAC_RESOLUTION (9) // Set this value to 9, 8, 7, 6 or 5 to adjust the resolution.
- void setup() {
- // Initiates serial communication, so we can send our data to our computer.
- Serial.begin(9600);
- // Initialize the INA219 sensor (current sensor).
- ina219.begin();
- // Initialize our DAC breakout boards.
- dac_v_ds.begin(0x62); // 0x62 sets the hex address of dac_v
- //HERE ADD A SECOND DAC FOR GATE VOLTAGE, WITH ADDRESS 0x63
- dac_v_g.begin(0x63);
- //
- }
- void loop() {
- // Set a voltage to the MOSFET Gate and sweep DAC_VDS Voltage to the Drain/Source pins,
- // read corresponding Voltage and Current across the MOSFET at VDS each step.
- //HERE SET YOUR GATE VOLTAGE DAC TO 5V VIA .setVoltage() FUNCTION CALL
- dac_v_g.setVoltage(5.0*4095/5.0,false);
- //
- //HERE MEASURE THE GATE VOLTAGE USING analogRead(0) FUNCTION (READS VOLTAGE AT PIN A0)
- //AND PRINT MEASURED GATE VOLTAGE TO SERIAL TERMINAL.
- Serial.println(analogRead(0));
- //
- //
- // Print table headers to serial port.
- Serial.print("Volts DS");
- Serial.print(" ");
- Serial.println("I_FET");
- // Sweep dac_v from 0 to 5V (approximately… may be lower due to BJT stage).
- for (int i = 0; i < 4096; i += 20) {
- dac_v_ds.setVoltage(i, false);
- delay(5); // Delay for 5ms to stabilize circuit.
- // Read VDS and ID at/across MOSFET.
- Serial.print(ina219.getBusVoltage_V()); // Reads voltage V at MOSFET Drain/Source.
- Serial.print(" ");
- Serial.println(ina219.getCurrent_mA()); // Reads current I through MOSFET.
- // To prevent overheating from excessive current we shut down V for a few ms.
- // We are effectively pulsing the MOSFET to ensure we don’t exceed
- // maximum power dissipation (P_max) rating.
- dac_v_ds.setVoltage(0, false); // Set VDS to 0V to allow cooling.
- delay(50); // Delay 10ms to allow MOSFET to cool.
- }
- // Uncomment delay() below if you prefer your program to stop for a time after an IV collection.
- //delay(300000);
- }
Advertisement
Add Comment
Please, Sign In to add comment