ARDUINO PURE SINE WAVE INVERTER WITH FEEDBACK

ARDUINO PURE SINE WAVE INVERTER WITH FEEDBACK Projects General Guidance January 24, 2019, 4:26am 1

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(); }

January 24, 2019, 4:39am 2

For informed help, please read and follow the directions in the "How to use this forum" post.

Edit your post to add code tags, clearly explain the problems you are having and remove the ALL CAPS SHOUTING.

Finally, a clear, complete schematic circuit diagram with properly identified components, and complete code required.

January 24, 2019, 6:05am 3

That code is incomplete (it misses a loop() function).

That commented-out "sinData.h" is what I guess you refer to as "the header". That's likely to be part of some kind of library, normally coming together with a .cpp file containing a number of functions. Those all would have to be re-written, but in order to do so you first have to know exactly what those functions are supposed to do.

If you don't know this, we certainly don't know, so the only advice I can give is contact the vendor.

January 24, 2019, 8:24am 4

It appears that it contained a sine table (byte array in progmem ) and its length. But could be much more, depending on what , if anything, was in loop(). Possibly a full sine wave running from 127 .. 255 .. 127 .. 0 .. 127 with intermediate values determined by the resolution. Here is one example: https://www.instructables.com/id/Arduino-Sinewave-for-Inverters/

It could have looked something like this:

// sinData.h #ifndef _SINDATA_H_ #define _SINDATA_H_ // from http://vk4ffab.info/2017/06/28/so-you-want-to-make-a-sine-wave-in-arduino/ // table of 256 sine values / one sine period / stored in flash memory PROGMEM const byte sinewave_data[] = {   127, 130, 133, 136, 139, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 176, 178, 181, 184, 187, 190, 192, 195, 198, 200, 203, 205, 208, 210, 212, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 234, 236, 238, 239, 240,   242, 243, 244, 245, 247, 248, 249, 249, 250, 251, 252, 252, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 253, 253, 253, 252, 252, 251, 250, 249, 249, 248, 247, 245, 244, 243, 242, 240, 239, 238, 236, 234, 233, 231, 229, 227, 225, 223,   221, 219, 217, 215, 212, 210, 208, 205, 203, 200, 198, 195, 192, 190, 187, 184, 181, 178, 176, 173, 170, 167, 164, 161, 158, 155, 152, 149, 146, 143, 139, 136, 133, 130, 127, 124, 121, 118, 115, 111, 108, 105, 102, 99, 96, 93, 90, 87, 84, 81, 78,   76, 73, 70, 67, 64, 62, 59, 56, 54, 51, 49, 46, 44, 42, 39, 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 16, 15, 14, 12, 11, 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 23, 25, 27, 29, 31,   33, 35, 37, 39, 42, 44, 46, 49, 51, 54, 56, 59, 62, 64, 67, 70, 73, 76, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105, 108, 111, 115, 118, 121, 124 }; sinewave_length = 256 ; #endif July 24, 2019, 9:58am 5

how make circuit this code???

Topic Replies Views Activity
Programing for pure sine wave inverter Programming 27 368 September 6, 2025
How to make inverter with arduino and mosfet General Guidance 11 3754 June 25, 2024
Pure Sine Wave Inverter General Guidance 33 30474 May 5, 2021
Sanity Check on Square Wave Generation Code Programming 35 390 September 12, 2025
Arduino inverter Programming 22 1803 September 23, 2022
Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Tag » Arduino Pwm Inverter Code