Guest User

rohan chopra

a guest
Nov 20th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "Wire.h"
  2. #include "SPI.h"
  3. #include "Adafruit_MCP4725.h" // DAC library
  4. #include "Adafruit_INA219.h" // INA219 current sensor library
  5. // Declare a current sensor object.
  6. Adafruit_INA219 ina219; // Commands like ina219.getCurrent_mA() will read the current.
  7. // Declare our voltage supply objects.
  8. Adafruit_MCP4725 dac_v_ds;
  9. //HERE DECLARE A SECOND DAC OBJECT TO BE USED TO SET GATE VOLTAGE (e.g. DAC_V_G)
  10. Adafruit_MCP4725 dac_v_g ;
  11. //
  12. #define DAC_RESOLUTION (9) // Set this value to 9, 8, 7, 6 or 5 to adjust the resolution.
  13. void setup() {
  14. // Initiates serial communication, so we can send our data to our computer.
  15. Serial.begin(9600);
  16. // Initialize the INA219 sensor (current sensor).
  17. ina219.begin();
  18. // Initialize our DAC breakout boards.
  19. dac_v_ds.begin(0x62); // 0x62 sets the hex address of dac_v
  20. //HERE ADD A SECOND DAC FOR GATE VOLTAGE, WITH ADDRESS 0x63
  21. dac_v_g.begin(0x63);
  22. //
  23. }
  24. void loop() {
  25. // Set a voltage to the MOSFET Gate and sweep DAC_VDS Voltage to the Drain/Source pins,
  26. // read corresponding Voltage and Current across the MOSFET at VDS each step.
  27. //HERE SET YOUR GATE VOLTAGE DAC TO 5V VIA .setVoltage() FUNCTION CALL
  28. dac_v_g.setVoltage(5.0*4095/5.0,false);
  29. //
  30. //HERE MEASURE THE GATE VOLTAGE USING analogRead(0) FUNCTION (READS VOLTAGE AT PIN A0)
  31. //AND PRINT MEASURED GATE VOLTAGE TO SERIAL TERMINAL.
  32. Serial.println(analogRead(0));
  33. //
  34. //
  35. // Print table headers to serial port.
  36. Serial.print("Volts DS");
  37. Serial.print(" ");
  38. Serial.println("I_FET");
  39. // Sweep dac_v from 0 to 5V (approximately… may be lower due to BJT stage).
  40. for (int i = 0; i < 4096; i += 20) {
  41. dac_v_ds.setVoltage(i, false);
  42. delay(5); // Delay for 5ms to stabilize circuit.
  43. // Read VDS and ID at/across MOSFET.
  44. Serial.print(ina219.getBusVoltage_V()); // Reads voltage V at MOSFET Drain/Source.
  45. Serial.print(" ");
  46. Serial.println(ina219.getCurrent_mA()); // Reads current I through MOSFET.
  47. // To prevent overheating from excessive current we shut down V for a few ms.
  48. // We are effectively pulsing the MOSFET to ensure we don’t exceed
  49. // maximum power dissipation (P_max) rating.
  50. dac_v_ds.setVoltage(0, false); // Set VDS to 0V to allow cooling.
  51. delay(50); // Delay 10ms to allow MOSFET to cool.
  52. }
  53. // Uncomment delay() below if you prefer your program to stop for a time after an IV collection.
  54. //delay(300000);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment