Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sinewave Inverter

Status
Not open for further replies.

Jasmine Kay

New Member
Hi friends,

I m trying to build sinewave inverter using PIC mcu from Microchip. I go through its PICREF-1 app. note and have some idea. I think I m clear ur to generation of sinewave but not clear about the feed back control. Any body help me to understand ? How to calculate the componseter. I m also not expert at C so could not understand fully the code.

Pl help me..

Jasmine Kay
 
:) There is a lot of information on the microcontroller forum on the electro tech online forum. Please go under search and look all the products about sinewave inverters, there are a lot of usuful information. I will provide you with more links ahead.
 
I try to find out in the forum but I dont get the exact Information I want. Any body please help me with the feedbac loop codes ? Its written there in MPLABC V 1.21. I want to re-write it in ASM any body can give me the Psudo Code of that or how to Improve it. I am Actully not expert but I think I can program what I think.... with some limitaions ofcourse..


Thanks
 
Friedns I pest the codes following for ready referance:
//#define OPEN_LOOP
#define FEEDBACK
//#define 50Hz
#define 60Hz
#pragma option v
#include <17c43.h>
#include <math.h>
#include <delay16.h>
#ifdef OPEN_LOOP

// This table yields Full VRMS input
unsigned char const pwmtab[32]={0,25,50,74,98,120,142,162,180,197,212,
225,235,244,250,254,255,254,250,244,235,
225,212,197,180,162,142,120,98,74,50,25};
#endif
#ifdef FEEDBACK
// This table yields slightly less than Full VRMS input
unsigned char const pwmtab[32]={0,20,40,60,79,97,114,131,145,159,171,
181,189,197,202,205,206,205,202,197,189,
181,171,159,145,131,114,97,79,60,40,20};
#endif
long read_ad(unsigned char); // Prototype for A/D converter function
unsigned char index; // Index into the sinewave reference table
unsigned char sign; // Flag used to unfold sinewave reference table
long reference; // Value of the sinewave refrence after unfolding
unsigned char reference_lo @ reference; // V1.21 of Compiler does not type cast unsigned
// char to long so we will write to low byte separately
long out_volt; // Magnitude of the output voltage;
long y; // Variables used in compensation routine
long yold;
long x;
long xold;
long ad_value; // A/D Converter Value
void main(void)
{
CLRWDT();
PORTC = 0; // Zero out portc latches
DDRC = 0x22; // Set up Data direction register for C
DDRB = 0; // Set up Data direction register for B
PR1 = 0xFF; // Setup PR1 register (24.4Khz @ 25Mhz clk)
PW1DCL = 0; // Set low bits of PWM to 0
PW1DCH = 0; // Init PWM duty cycle to 0
T0STA = 0x20; // Configure Timer0 prescaler
INTSTA.T0IE = 1; // Enable Timer 0 interrupt
TCON1.TMR1CS = 0;
TCON1.T16 = 0;
TCON2.TMR1ON = 1; // Start timer 1 (PWM timer)
TCON2.PWM1ON = 1; // Turn on the PWM
CPUSTA.GLINTD = 0; // Unmask the interrupts
index = 0; // Initialize variables
sign = 0;
y = 0;
yold = 0;
x = 0;
xold = 0;
PORTC.0 = 1; // Enable the Inverter
while(1); // Loop forever, execute in INT Routine
}
#ifdef FEEDBACK
__TMR0() // Timer interrupt
{
T0STA.T0CS = 0; // Stop timer
PORTB.7=1;
#ifdef 60Hz
TMR0L=0xA5;
TMR0H=0xF9; // Make Timer0 interrupt at 3.84KHz for 60Hz output
#endif
#ifdef 50Hz
TMR0L=0x5F; // Make Timer0 interrupt at 3.20KHz for 50Hz output
TMR0H=0xF8;

#endif
T0STA.T0CS = 1; // Start timer
CLRWDT();
reference = 0; // Clear Reference Value
reference_lo = pwmtab[index]; // Lookup the value of the sinewave reference
if (!index) // Toggle Sign Every Cycle Through table
sign = ~sign;
++index; // Increment index
if (index == 32) // If end of table, reset counter
index = 0;
if (sign) // If negative going wave
{
reference = ~reference; // V1.21 of Compiler negate (-ref) doesn’t work for
reference = reference + 1; // ref<=0
}
ad_value = read_ad(0);
out_volt = ad_value - 512; // Read output voltage (512 counts=0 volts out)
// Form the expression y = yold + (0.09261 * (x + xold))
// Where yold, xold is the value of y, x from the previous sample
// x is the <error signal>, formed by the difference between the output
// of the inverter and the reference signal.
x = out_volt - reference;
y = ((x + xold) * 24);
y = y / 256;
y = y + yold;
if (y >= 0)
{
PORTC.2 = 0; // Set positive going cycle
} else
{
PORTC.2 = 1; // Set negative going cycle
y = ~y;
y = y + 1;
}
if (y > 255)
y = 255; // Limit y
PW1DCH = y; // Update duty cycle
xold = x; // Store previous sample’s state
yold = y;
PORTB.7=0;
}
#endif
#ifdef OPEN_LOOP
// The inverter runs in an open loop mode with OPEN_LOOP defined.
__TMR0() // Timer interrupt
{
T0STA.T0CS = 0; // Stop timer
#ifdef 60Hz
TMR0L=0xA5;
TMR0H=0xF9; //Make Timer0 interrupt at 3.84KHz for 60Hz output
#endif
#ifdef 50Hz
TMR0L=0x5F; //Make Timer0 interrupt at 3.20KHz for 50Hz output
TMR0H=0xF8;
#endif
T0STA.T0CS=1; //Start timer
CLRWDT();
PW1DCH = pwmtab[index];
if (!index)
{
PORTC.0 = 0; // Gate Drive off
PICREF-1
PORTC.2 = ~PORTC.2; // Flip Pos/Neg bit
PORTC.0 = 1; // Gate Drive on
}
++index;
if (index == 32)
index = 0;
PORTC.3 = ~PORTC.3; // Toggle bit to test freq.
}
#endif
long read_ad(unsigned char channel)
{
long result;
PORTC.6 = 1; // Write bit high
PORTC.7 = 1; // Read bit high
PORTC.4 = 1; // Chip select high
DDRD = 0; // Make PORTD an output
PORTD = 0x04; // Single ended mode signed 10 bit chan 0 Right justified
PORTC.4 = 0; // Select chip
PORTC.6 = 0; // latch command word int A/D
PORTC.6 = 1; // Start conversion
PORTC.4 = 1; // Deselect chip
while (PORTC.5); // Wait for conversion to complete
DDRD = 0xFF; // Make PORTD an input
PORTC.4 = 0; // Select chip
PORTC.7 = 0; // Read high byte
*( ((unsigned char*)&result) + 1) = PORTD;
PORTC.7 = 1;
PORTC.4 = 1;
PORTC.4 = 0;
PORTC.7 = 0; // Read low byte
*( ((unsigned char*)&result) ) = PORTD;
PORTC.7 = 1;
PORTC.4 = 1; // Reset chip select lines
return (result); // Return data
}
 
DELLAY16.H REQUIRED

Hi, Miguel Gonzalez.
I NEED DELAY16.H FILE TO COMPILE MAIN.C OF PICREF 1. CAN U EXPLAIN WHAT DELLAY16.H DOES.. THANKS

Miguel Gonzalez said:
:) There is a lot of information on the microcontroller forum on the electro tech online forum. Please go under search and look all the products about sinewave inverters, there are a lot of usuful information. I will provide you with more links ahead.
 
<delay16.h>

Hi I am trying to generate sinusoidal pwm signals and I found PICREF-1 document on the internet but microchip made a mistake they put main c code to zipped main code and firmware. I am trying to find delay.16h file to make this example work. Can anyone help me???

Cheers
 
I have done that many times. I listened your suggestion and googled it again but the outcome was the same. I could not find it.

Thanks anyway...
 
Is this it? It's in **broken link removed**
"MPLAB-C User's Guide" (c) 1997 Microchip Technology Inc.
Code:
DELAY16.H
void Delay_Ms_25MHz(registerw delay);
Pause for delay milliseconds when operating at 25 MHz.
void Delay_Ms_20MHz(registerw delay);
Pause for delay milliseconds when operating at 20 MHz.
void Delay_Ms_16MHz(registerw delay);
Pause for delay milliseconds when operating at 16 MHz.
void Delay_Ms_8MHz (registerw delay);
Pause for delay milliseconds when operating at 8 MHz.
void Delay_Ms_4MHz (registerw delay);
Pause for delay milliseconds when operating at 4 MHz.
void Delay_Ms_2MHz (registerw delay);
Pause for delay milliseconds when operating at 2 MHz.
void Delay_Ms_1MHz (registerw delay);
Pause for delay milliseconds when operating at 1 MHz.
void Delay_Us_25MHz(registerw delay);
Pause for delay microseconds when operating at 25 MHz.
void Delay_Us_20MHz(registerw delay);
Pause for delay microseconds when operating at 20 MHz.
void Delay_Us_16MHz(registerw delay);
Pause for delay microseconds when operating at 16 MHz.
void Delay_10xUs_8MHz(registerw delay);
Pause for (delay times ten) microseconds when operating at 8 MHz.
void Delay_10xUs_4MHz(registerw delay);
Pause for (delay times ten) microseconds when operating at 4 MHz.
void Delay_10xUs_2MHz(registerw delay);
Pause for (delay times ten) microseconds when operating at 2 MHz.
 
PIC17C43 to dsPIC30F4011

The code has been written for pic17C43. Some of the timers and register names are different such as timer0 does not exist in dsPIC. Can anyone help me to do some changes and convert this code for dsPIC30F4011??? Even changing 2-3 lines would be very helpful for me.

Code:
void main(void)
{
CLRWDT();
PORTC = 0; // Zero out portc latches
DDRC = 0x22; // Set up Data direction register for C
DDRB = 0; // Set up Data direction register for B
PR1 = 0xFF; // Setup PR1 register (24.4Khz @ 25Mhz clk)
PW1DCL = 0; // Set low bits of PWM to 0
PW1DCH = 0; // Init PWM duty cycle to 0
T0STA = 0x20; // Configure Timer0 prescaler
INTSTA.T0IE = 1; // Enable Timer 0 interrupt
TCON1.TMR1CS = 0;
TCON1.T16 = 0;
TCON2.TMR1ON = 1; // Start timer 1 (PWM timer)
TCON2.PWM1ON = 1; // Turn on the PWM
CPUSTA.GLINTD = 0; // Unmask the interrupts
index = 0; // Initialize variables
sign = 0;
y = 0;
yold = 0;
x = 0;
xold = 0;
PORTC.0 = 1; // Enable the Inverter
while(1); // Loop forever, execute in INT Routine
}

#ifdef OPEN_LOOP
// The inverter runs in an open loop mode with OPEN_LOOP defined.
__TMR0() // Timer interrupt
{
T0STA.T0CS = 0; // Stop timer
TMR0L=0x5F; //Make Timer0 interrupt at 3.20KHz for 50Hz output
TMR0H=0xF8;
T0STA.T0CS=1; //Start timer
CLRWDT();
PW1DCH = pwmtab[index];
if (!index)
{
PORTC.0 = 0; // Gate Drive off
PORTC.2 = ~PORTC.2; // Flip Pos/Neg bit
PORTC.0 = 1; // Gate Drive on
}
++index;
if (index == 32)
index = 0;
PORTC.3 = ~PORTC.3; // Toggle bit to test freq.
}
#endif
 
Hi everyone,

I am woprking on an inverter and I am using dsPIC30F4011. I have found a sample code which is from "PICREF-1" document. The code has been written for pic17C43. Some of the timers and register names are different such as timer0 does not exist in dsPIC. Can anyone help me to do some changes and convert this code for dsPIC30F4011??? Even changing 2-3 lines would be very helpful for me.

Code:
void main(void)
{
CLRWDT();
PORTC = 0; // Zero out portc latches
DDRC = 0x22; // Set up Data direction register for C
DDRB = 0; // Set up Data direction register for B
PR1 = 0xFF; // Setup PR1 register (24.4Khz @ 25Mhz clk)
PW1DCL = 0; // Set low bits of PWM to 0
PW1DCH = 0; // Init PWM duty cycle to 0
T0STA = 0x20; // Configure Timer0 prescaler
INTSTA.T0IE = 1; // Enable Timer 0 interrupt
TCON1.TMR1CS = 0;
TCON1.T16 = 0;
TCON2.TMR1ON = 1; // Start timer 1 (PWM timer)
TCON2.PWM1ON = 1; // Turn on the PWM
CPUSTA.GLINTD = 0; // Unmask the interrupts
index = 0; // Initialize variables
sign = 0;
y = 0;
yold = 0;
x = 0;
xold = 0;
PORTC.0 = 1; // Enable the Inverter
while(1); // Loop forever, execute in INT Routine
}

#ifdef OPEN_LOOP
// The inverter runs in an open loop mode with OPEN_LOOP defined.
__TMR0() // Timer interrupt
{
T0STA.T0CS = 0; // Stop timer
TMR0L=0x5F; //Make Timer0 interrupt at 3.20KHz for 50Hz output
TMR0H=0xF8;
T0STA.T0CS=1; //Start timer
CLRWDT();
PW1DCH = pwmtab[index];
if (!index)
{
PORTC.0 = 0; // Gate Drive off
PORTC.2 = ~PORTC.2; // Flip Pos/Neg bit
PORTC.0 = 1; // Gate Drive on
}
++index;
if (index == 32)
index = 0;
PORTC.3 = ~PORTC.3; // Toggle bit to test freq.
}
#endif
 
Can anyone tell me that if you need to make complementary signals only 15% on time, what would you do? I mean in PWM module when you are using complementary mode can you make that complementary signal only 15% working? For instance PWM1L and its complementary PWM1H has only produce 15% of the signals in dsPIC30F4011...
 
Deadline : help needed of Sine Wave inverter

please any one help me

i need to make an inverter using PWM technique for my academic project

Please help me

i like to use the c code give nin the PICREF-1

but any one please help me to change this code of PIC 16F876 (which i had bought already!)

and anyone please tell me, how can i compile this C program and be checked using MP LAB?
I don't have any C compiler, other than Turbo C++.

Or, any other C Compiler can be downloaded? please


Please help me

my dead line is this 23rd Dec.

please help me
 
Hi
Has anyone successfully implemented this design? I am very much confused with the feedback algorithm. I feel there is a mistake in there.
Can anyone help.
Regards
Sudip
 
Hi everyone
i want to start work in sine wave inverter with H-bridge output can anybody help me what its waveforms will be for H-bridge, and also tel me how feedback work.
thanks
 
An inverter is a complicated machine

Hi,

For all those interested in the Microchip PICREF-1 Application Note. The code is C and you have to fully understand it.

But the mechanism is in understanding Frequency Compensation. There is a filter on the output of the UPS; a capacitor and an inductor. The capacitor puts (at least) one pole that has to be compensated with a zero. Or compared to a analog solution; you have to use a Error Amplifier with a capacitor and resistor; then you can put a cut-off-frequency in a low-pass filter (this is "digitalized" in the PICREF-1-solution).

When you understand that equation, you can go on with designing an UPS. And you can control much more than 1 kW; up to megawatt if you want to. And three-phase if you want to.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top