Created
November 6, 2017 11:31
-
-
Save yo3hjv/119db0521256e65e8bf0b6b8b65525e7 to your computer and use it in GitHub Desktop.
Pulse Frequency Modulation IGBT Controller with Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IGBT Pulse Frequency Modulation IGBT ControlleRev | |
// Rev 8.0 Final. | |
// Obverheating protection at 110 Celsius deg. | |
// Start self test | |
// Check this: http://damienclarke.me/code/posts/writing-a-better-noise-reducing-analogread for the | |
// analog noise reduction algorithm. | |
// Author: Adrian Florescu YO3HJV, nov. 2017 | |
// https://yo3hjv.blogspot.com/2017/11/pulse-frequency-modulation-igbt.html | |
#define lenght 16.0 | |
double percent=100.0; | |
unsigned char b; | |
unsigned int peace; | |
unsigned int adcM; | |
// Out PWM pin 9 | |
// Out relay pin 10 | |
// Temp DS18B pin 11 | |
// Pot wiper at A0 | |
int pinProt = 10; | |
// custom characters | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
// Noise reduction algorithm for reading analog value from the wiper | |
#include <ResponsiveAnalogRead.h> | |
const int ANALOG_PIN = A0; | |
ResponsiveAnalogRead analog(ANALOG_PIN, true); | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
// Data wire is plugged into port 11 on the Arduino | |
#define ONE_WIRE_BUS 11 | |
OneWire oneWire(ONE_WIRE_BUS); | |
// Pass our oneWire reference to Dallas Temperature. | |
DallasTemperature sensors(&oneWire); | |
float temp = 0; | |
int PWMfact = 0; | |
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address | |
#define lenght 16.0 | |
byte p1[8] = { | |
B10000, | |
B10000, | |
B10000, | |
B10000, | |
B10000, | |
B10000, | |
B10000, | |
B10000}; | |
byte p2[8] = { | |
B11000, | |
B11000, | |
B11000, | |
B11000, | |
B11000, | |
B11000, | |
B11000, | |
B11000}; | |
byte p3[8] = { | |
B11100, | |
B11100, | |
B11100, | |
B11100, | |
B11100, | |
B11100, | |
B11100, | |
B11100}; | |
byte p4[8] = { | |
B11110, | |
B11110, | |
B11110, | |
B11110, | |
B11110, | |
B11110, | |
B11110, | |
B11110}; | |
byte p5[8] = { | |
B11111, | |
B11111, | |
B11111, | |
B11111, | |
B11111, | |
B11111, | |
B11111, | |
B11111}; | |
// The temperature is checked at some intervals | |
unsigned long previousMillis = 0; // will store last time temp was updated | |
const long interval = 3000; // interval at which to check temp(milliseconds) | |
void setup() { | |
pinMode(pinProt, OUTPUT); | |
pinMode(9, OUTPUT); | |
lcd.init(); | |
lcd.backlight(); | |
lcd.setCursor(0, 0); | |
lcd.print("Self test"); | |
lcd.setCursor(0, 1); | |
lcd.print("Releu"); | |
delay(1000); | |
relayTest(); | |
lcd.clear(); | |
tempTest(); | |
delay(1000); | |
lcd.createChar(0, p1); | |
lcd.createChar(1, p2); | |
lcd.createChar(2, p3); | |
lcd.createChar(3, p4); | |
lcd.createChar(4, p5); | |
// Let's generate the PWM control signal. | |
pinMode(9, OUTPUT); TCCR1B = TCCR1B & 0b11111000 | 0x04; // 122 Hz control signal | |
pinMode(pinProt, HIGH ); // Activate relay push pull module | |
// Start up Sensor library | |
sensors.begin(); | |
Serial.begin(115200); | |
lcd.clear(); | |
} | |
void loop() { | |
unsigned long currentMillis = millis(); | |
if (currentMillis - previousMillis >= interval) { | |
previousMillis = currentMillis; | |
sensors.requestTemperatures(); | |
float temp = (sensors.getTempCByIndex(0)); | |
// Uncomment following lines for serial debugging | |
// Serial.print(temp); | |
// Serial.print("---"); | |
// Serial.println(percent); | |
if (temp == -127){ | |
lcd.setCursor(10, 1); | |
lcd.print(" "); | |
} | |
if (temp >110) { | |
pinMode(pinProt, LOW ); | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
lcd.print("DEPASIRE"); | |
lcd.setCursor(0, 1); | |
lcd.print("TEMPERATURA"); | |
exit(0); | |
} | |
if (temp>-30){ | |
lcd.setCursor(11, 1); | |
lcd.print(" "); | |
lcd.setCursor(14, 1); | |
lcd.print((char)223); | |
lcd.print("C"); | |
lcd.setCursor(11, 1); | |
lcd.print(temp, 0); | |
} | |
} | |
analog.update(); | |
unsigned int adcM = analog.getValue(); | |
// PWM from 5% to 98% otherwise On or OFF | |
if (adcM > 50 && adcM <= 1021) { | |
lcd.setCursor(6, 1); | |
lcd.print(" "); | |
PWMfact = map(adcM, 0, 1022, 0, 256); | |
analogWrite(9, -PWMfact);} | |
else if (adcM <= 49) {digitalWrite(9, HIGH); | |
lcd.setCursor(6, 1); | |
lcd.print("STOP"); | |
} | |
else if (adcM > 1021) {digitalWrite(9, LOW); | |
lcd.setCursor(6, 1); | |
lcd.print("FULL"); | |
} | |
percent = adcM/1024.0*100.0; | |
lcd.setCursor(0, 1); | |
lcd.print(" %"); | |
lcd.setCursor(0, 1); | |
lcd.print(percent, 0); | |
lcd.setCursor(0,0); | |
double a=lenght/95*percent; | |
if (a>=1) { | |
for (int i=1;i<a;i++) { | |
lcd.write(4); | |
b=i; | |
} | |
a=a-b; | |
} | |
peace=a*5; | |
switch (peace) { | |
case 0: | |
break; | |
case 1: | |
lcd.write((char)0); | |
break; | |
case 2: | |
lcd.write(1); | |
break; | |
case 3: | |
lcd.write(2); | |
break; | |
case 4: | |
lcd.write(3); | |
break; | |
} | |
for (int i =0;i<(lenght-b);i++) { | |
lcd.print(" "); } | |
} | |
void relayTest(){ | |
pinMode(9, HIGH); // block control PWM | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
pinMode(pinProt, HIGH ); | |
delay(20); | |
pinMode(pinProt, LOW); | |
delay(20); | |
} | |
// Overheat protection | |
void tempTest(){ | |
lcd.clear(); | |
sensors.requestTemperatures(); // Send the command to get temperatures | |
float temp = (sensors.getTempCByIndex(0)); | |
if (temp != -127) { | |
lcd.setCursor(0, 0); | |
lcd.print("Senzor termic"); | |
lcd.setCursor(0, 1); | |
lcd.print("prezent"); | |
} | |
else {lcd.setCursor(0, 0); | |
lcd.print("Senzor termic"); | |
lcd.setCursor(0, 1); | |
lcd.print("nu este prezent"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment