+ Reply to Thread
Results 1 to 14 of 14

Thread: Sine look up table for generating sine wave using pwm..

  1. #1
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default Sine look up table for generating sine wave using pwm..

    Hi to all!!!
    I am designing 3-phase AC induction motor speed controller drive using PWM inverter method.
    In that application I need to store sine look up table so that at every instant my 3 phases are seperated 120 degree with respect to each other,,,

    I read a particular 256 value sine table , but I don't know how this value comes??

    I am following microchip application note for this project..
    http://ww1.microchip.com/downloads/e...tes/00843a.pdf

    Can any one help out how to crack this??


    Sine table example
    // C 8-bit Sine Table
    const unsigned char sinetable[256] = {
    128,131,134,137,140,143,146,149,152,156,159,162,16 5,168,171,174,
    176,179,182,185,188,191,193,196,199,201,204,206,20 9,211,213,216,
    218,220,222,224,226,228,230,232,234,236,237,239,24 0,242,243,245,
    246,247,248,249,250,251,252,252,253,254,254,255,25 5,255,255,255,
    255,255,255,255,255,255,254,254,253,252,252,251,25 0,249,248,247,
    246,245,243,242,240,239,237,236,234,232,230,228,22 6,224,222,220,
    218,216,213,211,209,206,204,201,199,196,193,191,18 8,185,182,179,
    176,174,171,168,165,162,159,156,152,149,146,143,14 0,137,134,131,
    128,124,121,118,115,112,109,106,103,99, 96, 93, 90, 87, 84, 81,
    79, 76, 73, 70, 67, 64, 62, 59, 56, 54, 51, 49, 46, 44, 42, 39,
    37, 35, 33, 31, 29, 27, 25, 23, 21, 19, 18, 16, 15, 13, 12, 10,
    9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 3, 4, 5, 6, 7, 8,
    9, 10, 12, 13, 15, 16, 18, 19, 21, 23, 25, 27, 29, 31, 33, 35,
    37, 39, 42, 44, 46, 49, 51, 54, 56, 59, 62, 64, 67, 70, 73, 76,
    79, 81, 84, 87, 90, 93, 96, 99, 103,106,109,112,115,118,121,124
    };
    Attached Images


  2. #2
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    hi,
    A quick look at the table, shows that 128 represents the 0deg point on the sine curve, it increases to 255 which is 90degs then decreases thru 128 down to 0 which represents 270deg and then back upto 128 0deg.

    There is a tabulation printing error in the rightside of the data, and added 'space' that should be removed.


    16 5,.... 2 09 etc etc
    OK.?
    Last edited by ericgibbs; 11th August 2009 at 08:32 AM.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  3. #3
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default

    What is the logic behind these resulting values??
    How 128 refers to zero..???
    And how this value can be used to decide pwm frequency in software program?

  4. #4
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    Quote Originally Posted by mananshah93 View Post
    What is the logic behind these resulting values??
    How 128 refers to zero..???
    And how this value can be used to decide pwm frequency in software program?
    hi,
    The 128 numeric value is 80hex or 10000000 in 8 bit format.

    So in this application any hex value with bit 7 set to '1' is considered a positive value [0deg thru 180deg] and any hex value with bit7 set to '0' is a negative value [180deg thru 360deg].

    The program would read the decimal values as hex values and output the 8 bit data pattern onto a PIC dataport.
    This 8 bit output would drive a 8 bit digital to analog convertor to produce the required sine waveform.

    The frequency of the D2A sinewave is determined by the rate at which the table values are read and output.

    The faster the read/output rate the higher the frequency.

    For 3 phase operation, a 120deg phase shift is obtained by adding equal to 120deg or 240deg, to the value read from the table.

    OK.

    EDIT:
    Looking at the microchip datasheet, shows in this application the output drives the motor using a PWM signal derived from the table values and not an D2A.

    The datasheet explains how the program achieves this PWM signal.
    Attached Images
    Last edited by ericgibbs; 11th August 2009 at 09:55 AM.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  5. #5
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default

    ya, its not d2a, but your interpretation sounds correct regarding 8 bit...however how can we say it is providing 120 degree phase shift?
    I am not able to understand how to interpret equation 4 given in the datasheet??
    timer reload value= [FFFFh- ({Fosc/4}/sine samples per cycle *ADC)]
    I am not getting the logic behind this....

  6. #6
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    Quote Originally Posted by mananshah93 View Post
    ya, its not d2a, but your interpretation sounds correct regarding 8 bit...however how can we say it is providing 120 degree phase shift?
    I am not able to understand how to interpret equation 4 given in the datasheet??
    timer reload value= [FFFFh- ({Fosc/4}/sine samples per cycle *ADC)]
    I am not getting the logic behind this....
    hi,
    I read the formula components as:

    Fosc is the PIC crystal frequency, dividing this by 4 gives the internal clcok cycle for the PIC.

    Sine samples/cycle, is the number of elements in the sine table.

    Timer0 prescaler is the value loaded by the program into the Timer0 prescaler.

    The ADC is the output from the 10bit adc pot speed control.

    Look at this image, it explains 120deg offset.

    Is this what you mean.?
    Attached Images
    Last edited by ericgibbs; 11th August 2009 at 12:05 PM.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  7. #7
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default

    See, I understand the terms, but this derivation that I am not able to digest...see my aim is to produce these sine waves using similar concept..for that I need to program chip...as far as my understanding is concern , the sine table's respected values can be considered as variable for calculating on time of pwm...And at particular instant my 3 phase should be such that they should be having a on-time which lead them 120 degree phase shift.
    the question remains , how the value of sine table associated with calculation of pwm on time??

  8. #8
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    Quote Originally Posted by mananshah93 View Post
    the question remains , how the value of sine table associated with calculation of pwm on time??
    hi,
    Its all explained in the last image I posted.

    I have extracted the details in this image.
    Attached Images
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  9. #9
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default

    ok...I read that before, but...lets take one value..
    say value=128 and half value of ADC=512...
    Fosc=20Mhz, prescalar=1,sine samples=256
    now timer0 reload value= 38.14
    this is the time period between two states...
    now what about on time of pwm which will be applied during above time period..
    After every Timer0 overflow interrupt, the value pointed
    to by the offset registers on the sine table is read. The
    value read from the table is scaled based on the motor
    frequency input,
    by multiplying by the frequency input
    value to find the ratio of PWM, with respect to the maximum
    DC bus. This value is loaded to the corresponding
    PWM duty cycle registers.


    what is other input???Is that ADC value???

  10. #10
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    Quote Originally Posted by mananshah93 View Post

    what is other input???Is that ADC value???
    Its in datasheet and my earlier image, its the output from a speed pot thats digitised by the PIC adc input, giving a 10bit resolution value.
    Attached Images
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  11. #11
    marcbarker Good marcbarker Good marcbarker Good
    Join Date
    Jul 2009
    Location
    London, UK
    Posts
    728

    Default

    If it's any help, I work out this kind of problem using Microsoft Excel.

    "I think, therefore I toast" ( Mr. T. Toaster, artificial life form, kitchen appliance & Philosopher)

  12. #12
    ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent ericgibbs Excellent
    Join Date
    Jan 2007
    Location
    Hampshire. England.
    Posts
    10,756
    Blog Entries
    12

    Default

    Quote Originally Posted by marcbarker View Post
    If it's any help, I work out this kind of problem using Microsoft Excel.
    hi marc,
    I think is a case of the OP not reading the datasheet carefully and trying to use the applications data on a different project.
    Eric " Good enough is Perfect "
    I will NOT answer PM's requesting technical help, please use the Forum
    PIC tutorials: Nigel's www.winpicprog.co.uk/ Bill's: www.blueroomelectronics.com/

  13. #13
    tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent tcmtech Excellent
    Join Date
    Feb 2009
    Location
    Sawyer, North Dakota, USA
    Posts
    3,194
    Blog Entries
    2

    Default

    For what its worth there are many three phase driver IC's that do all of this for you!
    "When in doubt, LIGHT IT ON FIRE AND SEE WHAT COLOR OF SMOKE IT CAN MAKE!" -- tcmtech

  14. #14
    mananshah93 Newbie
    Join Date
    Sep 2008
    Posts
    86

    Default

    thanks to all!!!
    I have to rethink this matter, feeling lost this time...anyway thanks for your co-operation...

+ Reply to Thread

Similar Threads

  1. Generating sine wave and cosine wave
    By sp_vibes in forum Electronic Projects Design/Ideas/Reviews
    Replies: 7
    Latest: 9th November 2008, 06:22 PM
  2. Generating sine wave of 4kHz using PWM.
    By MrNobody in forum Micro Controllers
    Replies: 10
    Latest: 30th May 2008, 04:20 PM
  3. Converting a square wave into sine wave using a D/A converte
    By khalifemazen in forum Electronic Projects Design/Ideas/Reviews
    Replies: 6
    Latest: 21st May 2008, 11:21 PM
  4. Help...How to generate a quadrature signal (cos wave and sine wave)?
    By hykwei in forum Electronic Projects Design/Ideas/Reviews
    Replies: 2
    Latest: 9th May 2007, 05:52 PM
  5. LC filter- filtering a square wave to sine wave
    By kken6248 in forum General Electronics Chat
    Replies: 3
    Latest: 22nd April 2004, 05:32 AM

Tags for this Thread