Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to modify Sine wave table according to the input ADC

Status
Not open for further replies.

lalgpt

Junior Member level 3
Joined
Jan 25, 2012
Messages
30
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
India
Activity points
1,474
I found this code from net

const unsigned char wave[181] = {128,132,137,141,146,150,155,159,163,168,172,176,1 80,184,188,192,196,200,203,207,210,214,217,220,223 ,226,229,232,234,237,239,241,243,245,247,248,250,2 51,252,253,254,254,255,255,255,255,255,255,255,255 ,254,253,252,251,250,248,247,245,243,241,239,237,2 34,232,229,226,223,220,217,214,210,207,203,200,196 ,192,188,184,180,176,172,168,163,159,155,150,146,1 41,137,132,128,124,119,115,110,106,101,97,93,88,84 ,80,76,72,68,64,60,56,53,49,46,42,39,36,33,30,27,2 4,22,19,17,15,13,11,9,8,6,5,4,3,2,1,1,0,0,0,0,0,1, 1,2,3,4,5,6,8,9,11,13,15,17,19,22,24,27,30,33,36,3 9,42,46,49,53,56,60,64,68,72,76,80,84,88,93,97,101 ,106,110,115,119,124,128};

void main()
{
unsigned char i;
TRISD = 0x00;
for(i=0;i<181;i++)
{
PORTD = wave;
__delay_us(70);
}









How to modify i according to the ADC available
 

I think you have taken my table

form this link
https://www.edaboard.com/threads/236741/#post1011463
few months back i had asked some thing related to that...

What u want to do with the ADC, there is no need of adc.. i-fact a dac is used to produce a sine wave at the output of portd which is connected to dac

What is your application.. what you want to do...
 
  • Like
Reactions: lalgpt

    lalgpt

    Points: 2
    Helpful Answer Positive Rating
My aim is to produce a sine wave inverter. With a fixed reference modify the PWM according to the output
 

I am not getting you exactly...

This is what i got...

You want to generate the sine wave but to control its frequency using the PWM module...

If this is not what you want to say..
then please elaborate your question...

post your question.. i will reply after some time
 
  • Like
Reactions: lalgpt

    lalgpt

    Points: 2
    Helpful Answer Positive Rating
1. Inverter frequency is fixed to 50HZ, not varying with time.
2. Inverter output voltage is fixed, but will vary when loading.
3. so my aim is

#define ref_volt=5
read ADC, if ADC voltage is less than this "ref_volt=5" modify the sinetable[24]={4,5,6,7,9 etc}

- - - Updated - - -

verr=ref_volt-ADC_read

this verr is used to modify the tabel, If Verr=0 then output voltage is 230V

I wish to USE PIC18F452, ADC = 5V when output of the inveter = 230V

- - - Updated - - -


I have only basic idea in computer c programming, Electrical Engineering student, Using MicroC

regards
Lalgpt
 
Last edited:

  • Like
Reactions: lalgpt

    lalgpt

    Points: 2
    Helpful Answer Positive Rating
Re: How to modify Sine wave table according to the input ADC
1. Inverter frequency is fixed to 50HZ, not varying with time.
2. Inverter output voltage is fixed, but will vary when loading.
3. so my aim is

#define ref_volt=5
read ADC, if ADC voltage is less than this "ref_volt=5" modify the sinetable[24]={4,5,6,7,9 etc}

- - - Updated - - -

verr=ref_volt-ADC_read

this verr is used to modify the tabel, If Verr=0 then output voltage is 230V

I wish to USE PIC18F452, ADC = 5V when output of the inveter = 230V

- - - Updated - - -


I have only basic idea in computer c programming, Electrical Engineering student, Using MicroC

regards
Lalgpt
 

Hello,

you don't have to change the shape of sinus table,
but only the time beetwen sending each value.
so in your code example
modify delay(70); according the err value.


but the example uses an Digital to analog converter !
not PWM as you requierd.
 

I think, its about automatic voltage control. When load is increased and voltage is droped and after detecting this drop (or increase) through adc then change the values of sine table so that the generated voltage is stabilized. Am i right about analyzing your requirement?
 
  • Like
Reactions: lalgpt

    lalgpt

    Points: 2
    Helpful Answer Positive Rating
I used ten different sine tables with slight difference in an sinewave inverter based on 16f72. Table is selected according to adc level.
 

hello

if you only want to change the amplitude, not the frequency , you can use a digital potentiometer
to adjust DAC level output ,
driven by your calculated "error" ( target-measure)
it's more simple.

You will have to use interupt to manage the sine signal generation , independantly
of the voltage control, which can disturb the timming .
Take care about Time constraint , speed of controller
and how many task to do , in "like real time ".

Not enough data to help you in this project ...
 

What if output is from pwm output pin and not from dac connected to port.
 
Last edited:

yes exactly

- - - Updated - - -

sine table values are determining the Ton period, we have to modify that instantaneously

- - - Updated - - -

Output voltage is derived from the actual inverter output variation 0 to 230Ac is converted to 0 to 5V DC
 

Hi lalgpt,Alterlinks,
a sine table is used with the pwm to generate 50 hz you will get half wave from the above table 181. you have to make another table for sinewave correction. the error voltage you get from the the output is compared to a standard value and correction digit from the correction table is added in case o/p is less and deducted in case the o/p is more fore each pulse when incrementing i. if you want correction to be done you should not use values upto 255 in main table. because you cannot add a correction to that value.if anybody find this usefull just click helped me button.
regards ani

- - - Updated - - -

Hi,
you can use table like this(181)
123,127,131,135,139,144,148,152,156,160,164,168,172,176,180,183,187,191,194,198,201,204,207,210,213,216,219,221,224,226,228,230,232,234,236,
237,239,240,241,242,243,244,244,245,245,245,245,245,244,244,243,243,242,241,239,238,237,235,233,231,229,227,225,222,220,217,215,212,209,
206,203,199,196,192,189,185,182,178,174,170,166,162,158,154,150,146,142,137,133,129,125,120,116,112,108,103,99,95,91,87,83,79,75,71,67,
63,60,56,53,49,46,42,39,36,33,30,28,25,23,20,18,16,14,12,10,8,7,6,4,3,2,2,1,1,0,0,0,0,0,1,1,2,3,4,5,6,8,9,11,13,15,17,19,21,24,26,29,32,
35,38,41,44,47,51,54,58,62,65,69,73,77,81,85,89,93,97,101,106,110,114,118,
regards ani
 

correction table is added in case o/p is less and deducted in case the o/p is more fore each pulse

Is this method more precise than seperate complete tables? I guess there is more error introduced in values of sine table generated due to small values of error table causing distortion.
How about pi correction? A method used by someone else in his words
In my design I sample the output voltage (a dc average) pass it through a PI routine to derive error. The error is basically and inverse of my sinewave modulating quotient. Which gets multiplied with the look up table. To save instruction cycles during table interrupts the entire lookup table is recalculated during zero cross for a cycle and kept in an array. This does not result in a highly pure sine but THD measured was between 2.5% and 4%. Thus waves are corrected only every 10mS. In fact 20mS was the original design to avoid flux imbalance. Now the routine uses flux reset by just switching on the Lower MOSFETs every zero cross. This gives me enough time for housekeeping etc. Like battery capacity measurement, display, communication, discharge profile log and possible econo-mode change during long power outage hours based on previous history.
All done on a 18F4520 @ 40MHz.
 

Hi Alterlinks,
Yes, as you told this is not a precise method you will only only get the output voltage in a particular range in my method which is simple to do. Recalculating the table in between interrupts is a good idea. I so far did not attempt such a design is it possible on 16f877a @ 20mhz.
regards ani
 

Can you give that idea to correct the sine table with PI
 

Hi lalgpt,
lalgpt the max value on the sine table is 255 so if you are using a table with peak value 255 u cannot increase the output v . so u have to use a sine table as in my post no15 to generate output(in this table i kept 245 as max value). u can make a sine table with 10 as peak and name as correction table. u can measure as u said with adc the o/p v and add the correction table to the main sine table if the o/p is less or u can subtract the correction table from the main sine table if the o/p is more.hope this helped.i did not understand what u meant by PI.
regards ani
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top