PLEASE I NEED HELP WITH THIS PROJECT. IM HAVING DIFFICULTY WRITING THE INVERTER CODES, THE ONES I WROTE DIDNT WORK, SO I RESULTED TO BUYING ONE.. BUT I LOST THE HEADER FILE. BELOW IS THE CODE. PLEASE CAN SOMEONE HELP WITH HOW TO GO ABOUT WITH THE HEADER FILE, OR IDEAS ON HOW TO WRITE IT
//#include "sinData.h"
#define MaxVoltage 1000
#define MinVoltage 600
#define MaxFreq 60
#define MinFreq 5
#define MaxCurrent 800
int Voltage;
int Current;
int flagShutDown;
bool flagBtnSpeedDn;
bool flagBtnSpeedUp;
float Frequency;
#define pinShutDown 4
#define pinADCCurrent A2
#define pinADCVoltage A0
#define pinOverVoltageLED 2
#define pinUnderVoltageLED 5
#define pinOverCurrentLED 3
#define pinOperationRelay 9
#define pinBtnSpeedUp 10
#define pinBtnSpeedDn 11
#define pinPWMOutput 6
void ShutDown()
{
digitalWrite(pinShutDown, HIGH);
digitalWrite(pinOperationRelay, LOW);
flagShutDown = true;
}
void InitPinMode()
{
pinMode(pinShutDown, OUTPUT);
pinMode(pinOverVoltageLED, OUTPUT);
pinMode(pinUnderVoltageLED, OUTPUT);
pinMode(pinOverCurrentLED, OUTPUT);
pinMode(pinOperationRelay , OUTPUT);
pinMode(pinBtnSpeedUp, INPUT);
pinMode(pinBtnSpeedDn, INPUT);
pinMode(pinPWMOutput, OUTPUT);
}
void InitStatus()
{
flagShutDown = false;
Frequency = 50;
flagBtnSpeedDn = true;
flagBtnSpeedUp = true;
digitalWrite(pinShutDown, LOW);
digitalWrite(pinOverVoltageLED, LOW);
digitalWrite(pinUnderVoltageLED, LOW);
digitalWrite(pinOverCurrentLED, LOW);
digitalWrite(pinOperationRelay, LOW);
digitalWrite(pinBtnSpeedUp, HIGH);
digitalWrite(pinBtnSpeedDn, HIGH);
}
void CheckFaults() {
Voltage = analogRead(pinADCVoltage);
delay(50);
if (Voltage > MaxVoltage) {
ShutDown();
digitalWrite(pinOverVoltageLED, HIGH);
}
if (Voltage < MinVoltage) {
ShutDown();
digitalWrite(pinUnderVoltageLED, HIGH);
}
Current = analogRead(pinADCCurrent);
delay(50);
if (Current > MaxCurrent) {
ShutDown();
digitalWrite(pinOverCurrentLED, HIGH);
}
}
volatile uint16_t sample;
ISR(TIMER1_COMPA_vect) {
if (sample >= sinewave_length) {
sample = -1;
} else {
OCR0A = pgm_read_byte(&sinewave_data[sample]);
}
++sample;
}
void UpdateFreq()
{
OCR1A = F_CPU / (256 * Frequency);
}
void startPWM()
{
TCCR0A |= _BV(WGM01) | _BV(WGM00);
TCCR0B &= ~_BV(WGM02);
TCCR0A = (TCCR0A | _BV(COM0A1)) & ~_BV(COM0A0);
TCCR0A &= ~(_BV(COM0B1) | _BV(COM0B0));
TCCR0B = (TCCR0B & ~(_BV(CS02) | _BV(CS01))) | _BV(CS00);
OCR0A = pgm_read_byte(&sinewave_data[0]);
cli();
TCCR1B = (TCCR1B & ~_BV(WGM13)) | _BV(WGM12);
TCCR1A = TCCR1A & ~(_BV(WGM11) | _BV(WGM10));
TCCR1B = (TCCR1B & ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);
UpdateFreq();
TIMSK1 |= _BV(OCIE1A);
sample = 0;
sei();
}
void setup()
{
InitPinMode();
InitStatus();
startPWM();
}