Select Page

Arduino Code

 

#include <PWM.h> // Include PWM Library
#include <TM1637Display.h> // Include TM1637 Display Libray

// Declare Setting
float D=0; // Duty Cycle
float Dmin = 10; // Minimum Duty Cycle (%)
float Dmax = 65; // Maximum Duty Cycle (%) (DO NOT MORE THAN 0.8 FOR BOOST)
int Rleft= 930; // Left Input Sense Receive at ADC (0-255 depend on resistance)
int32_t Fs = 70000; // Switching Frequency (in Hz)
int Dout; // Duty Cycle (0-255)
int R=0; // ADC Input (0-255)

// Declare Input Output
int dPin = A0; // Duty Cycle Pin
int pwmPin = 10; // PWM Pin
#define CLK 3 // Define CLK pin for TM1637 Display
#define DIO 2 // Define DIO pin for TM1637 Display
TM1637Display display(CLK, DIO); // Create TM1637 Display Class

void setup() {
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(pwmPin, Fs);
//if the pin frequency was set successfully, turn pin 13 on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}

pinMode(dPin,INPUT); // Declare dPin as input
Serial.begin(9600); // Declare display parameter in PC
display.setBrightness(0x0f); // Set the display brightnes
}

void loop() {
R=analogRead(dPin); // Read ADC
if (R>=Rleft){ // Limit ADC Input
R=Rleft;
}
if (R<=0){
R=0;
}

D=(Dmin-Dmax)/Rleft*R+Dmax; // Calculate actual D based on ADC
Dout = D/100*255; // Convert D into 8 Bit Format (0-255)
pwmWrite(pwmPin, Dout); // D change from 0 to 255
Serial.println(R); // Print in PC
Serial.println(D); // Print in PC
Serial.println(Dout); // Print in PC
display.clear(); // Clear TM1637 Display
display.showNumberDec(D, false); // Print D to Tm1637 Display
delay(500); // Add delay to avoid noise problem
}

Description

The module is created for the third year specialized power electronic laboratory. A set of the experiment consit of 2 PCB board.

The PWM Generator Board generates the required signal to switch the MOSFET. The potentiometer allows the change of duty cycle for the PWM. This board also equipt with a 7-segment LED TM1637 display to show the duty cycle.

The Converter Board provides the buck, boost, or buck-boost converters connections. This is achieved by vary the location of the MOSFET, inductor, and diode. The location of the capacitor, load, and voltage source remain intact.

List of Materials

  1. Terminal Block DG128V-02 x14
  2. Terminal Block DG128V-03 x2
  3. PCB Connector Header 2 Ways 2600 x12
  4. PCB Connector Housing 2 Ways 2510 x6
  5. PCB Stand 12mm x24
  6. IC Socket 8 Pin x2
  7. Potentiometer 10 kohm x2
  8. Arduino Female Header 1×6 Ways x6
  9. Arduino Female Header 1×8 Ways x2
  10. Banana Plug Red x6
  11. Banana Plug Black x6
  12. Crocodile Clip Red x2
  13. Crocodile Clip Black x2
  14. Resistance 240 ohm 0.5W x2
  15. Resistance 1 kohm 0.5W x2
  16. Resistance 5 ohm 0.5W x2
  17. Resistance 100 ohm 100 W x2
  18. Resistance 200 ohm 50 W x2
  19. Resistance 10 ohm 50 W x2
  20. Resistance 50 ohm 20W x2
  21. Electrolytic Capacitor 47uF 100V x2
  22. Electrolytic Capacitor 20 uF 100V x2
  23. Electrolytic Capacitor 100 uF 100V x2
  24. Wire 1.5mm Red x1.5m
  25. Wire 1.5mm Black x1.5m
  26. Wrapping Wire AWG30 Red x1.5m
  27. Wrapping Wire AWG30 Black x1.5m
  28. Arduino Uno x2
  29. TM1637 Display x2
  30. PCB 15cm x 20cm x2
  31. MOSFET (>100V >3A) x2
  32. Diode (>3A) x2
  33. Toroid (>3cm) x2