sinusoidal PWM


Closed Thread
Results 1 to 40 of 84

Thread: sinusoidal PWM

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    37

    Default sinusoidal PWM

    Hi there,i'm new to this forum,m learning the PIC BASIC PRO programming and now i want to generate a sinusoidal pulse width modulated signal by using pic16f877 microcontroller,please i need some ideas on how to go about it and code example to start with....

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hello and welcome to the forum.

    Microchip has an application note for sine wave with the 16F series chip. They show two ways to do it, one with PWM and the next with a resistor ladder. http://ww1.microchip.com/downloads/e...tes/00655a.pdf

    The PIC18F2431 and PIC18F4431 have some great features for multi pwm sine waves. So recently most of the examples use this chip.

    Here are a few examples: http://www.picbasic.co.uk/forum/cont...-DT-interrupts

    http://www.picbasic.co.uk/forum/showthread.php?t=14359

    You can also enter a search for sine and get some more.

  3. #3
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    thanx..m working on them

  4. #4
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi,i've read the Microchip appliction notes for sine wave with the 16F series chip..http://ww1.microchip.com/downloads/en/AppNotes/00655a.pdf together with the examples given in http://www.picbasic.co.uk/forum/content.php?r=229-Sine-wave-using-DT- interrupts and http://www.picbasic.co.uk/forum/showthread.php?t=14359.

    there are number of things which i've not understand from these readings and i'm asking for help from anyone who can help me to understand.these things are:
    1)how to generate a lookup table for the sine waveforms
    2)how to include DT_INTS-18.bas file so that when i compile,the compiler will be able to open it
    3)what is the purpose of this piece of code from example of http://www.picbasic.co.uk/forum/cont...-DT-interrupts

    asm
    __CONFIG _CONFIG1H, _OSC_HSPLL_1H
    __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WDPS_512_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    endasm

    thank you in advance.

  5. #5
    Join Date
    Oct 2005
    Location
    Loveland CO USA
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    1) You could use the 32 location array you pointed at in question 3. I used M.S. EXCEL.
    3) Get the data sheet for the PIC in PDF format and search for _OSC_HSPLL_1H or some piece of that. In the first of the 3 you can see these bits setup the oscillator and PLL. Most of the PICs have many modes for the oscillator. Internal/ external, divide by 32/ multiply by 4, etc.

    1)how to generate a lookup table for the sine waveforms
    2)how to include DT_INTS-18.bas file so that when i compile,the compiler will be able to open it
    3)what is the purpose of this piece of code from example of http://www.picbasic.co.uk/forum/cont...-DT-interrupts

    asm
    __CONFIG _CONFIG1H, _OSC_HSPLL_1H
    __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WDPS_512_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L
    endasm

    thank you in advance.[/QUOTE]

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    to bwaxing:

    My advice : read this great post with exemples, the sine is stored in an array :
    http://www.picbasic.co.uk/forum/cont...-DT-interrupts
    Last edited by Ioannis; - 8th May 2011 at 15:32.

  7. #7
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    thanks for the advice,i read examples from that post and I've not understand how to create the lookup table.From that post sine is stored in the array and i don't understand how the value for a particular step have been determined.for example i want to use 8-bit resolutions (256 steps),how will i determine the value of each step?is there a formula or something?
    thanks again.
    Last edited by Ioannis; - 8th May 2011 at 15:32.

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    The max I see most people do is a 72 step lookup or array. (36 or 72 steps makes it easier to off set for multiple phases). The resistor capacitor filter smooths out the steps. It is still 8 bit resolution, even with 32 or 36 steps. If you wanted to have each value be more accurate, you could use 10 bits in your values for each step.
    Last edited by ScaleRobotics; - 2nd March 2011 at 17:37. Reason: 8 bit resolution

  9. #9
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Red face Re: sinusoidal PWM

    Hi,
    thanks for the tip,m trying to modify the example you gave in http://www.picbasic.co.uk/forum/cont...-DT-interrupts so that i can generate a 50Hz sinusoidal PWM signal to control a single phase inverter using pic16f877.If i understand u correctly,in the sine array you jumped four steps to get 128 steps of 8-bit resolution,but how you got the correspond value for each step is not clear to me,i want to learn how to create a lookup table the way you did as i dont know how to create it using excel.what formula was used to get these values from that example?
    ; Set sine "table" in an array
    sineval var byte[32]
    sineval[1] = 128
    sineval[2] = 148
    sineval[3] = 167
    sineval[4] = 185
    sineval[5] = 200 etc.

    Also for 50Hz,PR2 will be loaded with 78 for 20MHz oscillator frequency of 16f877,but i dont how to arrive in determination of the value loaded for variable'' timerone''.

    When i copied the example and try to compile i got the warning 'unable to open include file DT_INTS-18.bas'..what should i do about this?

    Finally,is there any other modification i should do in that program that it could work better in pic16f877?
    Last edited by Ioannis; - 8th May 2011 at 15:33.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    You have to download Darrel Taylor's interrupts system : http://darreltaylor.com/DT_INTS-14/intro.html

    And put the "DT_INTS-14.bas", etc. into the folder of your source files.
    Last edited by Ioannis; - 8th May 2011 at 15:34.

  11. #11
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Unhappy Re: sinusoidal PWM

    Hi,
    i have download DT_INTS-14.bas" and DT_INTS-18.bas files and put them in the folder of my source files,when i try to compile the program again the same warning appeared again "unable to open INCLUDE file DT_INTS-18.bas"!
    Last edited by Ioannis; - 8th May 2011 at 15:34.

  12. #12
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Quote Originally Posted by bwaxing View Post
    Hi,
    i have download DT_INTS-14.bas" and DT_INTS-18.bas files and put them in the folder of my source files,when i try to compile the program again the same warning appeared again "unable to open INCLUDE file DT_INTS-18.bas"!
    You would need to change the include statement, so that it is using DT_INTS-14 instead of DTS_INTS-18. 18 is for PIC18's, DT_INTS-14 is for lower chips, like PIC17,PIC16 and PIC12's.

    Then there are probably different registers that will give you errors, etc. You should be able to change it, (and also the configs), but it will be a little work.

  13. #13
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Smile Re: sinusoidal PWM

    hi everybody,

    i'm here again with the sinusoidal PWM, please bear with me,

    It seems there were some problems with my compiler but after re-installing it,things work pretty well,i've included the file DT_INTS-14.bas in the folder containing the source code and although there some errors,its a good start to me.
    there are few things which are not clear to me from the example ofhttp://www.picbasic.co.uk/forum/cont...-DT-interrupts
    How to obtain the correspond value for each step is not clear to me,i want to learn how to create a lookup table the way it is done in the example as i dont know how to create it using excel.what formula was used to get these values from that example?
    ; Set sine "table" in an array
    sineval var byte[32]
    sineval[1] = 128
    sineval[2] = 148
    sineval[3] = 167
    sineval[4] = 185
    sineval[5] = 200 etc.

    Also for 50Hz,PR2 will be loaded with 78 for 20MHz oscillator frequency of 16f877,but i dont how to arrive in determination of the value loaded for variable'' timerone''.

    Should i include DT_INTS-18.bas file or DT_INTS-14.bas file?it seems to me they perform different functions!which link will i get DT_INTS-18.bas file?

    Finally,is there any other modification i should do in that program that it could work better in pic16f877?

    Thank you in advance.
    Last edited by Ioannis; - 8th May 2011 at 15:34.

  14. #14
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    I don't think your chip has a PLL. So its always best to go with the default configs when you try to change chips. So if you just erase this from the code:
    Code:
    asm
        __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
        __CONFIG    _CONFIG2H, _WDTEN_OFF_2H & _WDPS_512_2H
        __CONFIG    _CONFIG4L, _LVP_OFF_4L
    endasm
    It will use the defaults located in PBP under your chipname.inc

    Then you will get less errors

  15. #15
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Quote Originally Posted by scalerobotics View Post
    I don't think your chip has a PLL. So its always best to go with the default configs when you try to change chips. So if you just erase this from the code:
    Code:
    asm
        __CONFIG    _CONFIG1H, _OSC_HSPLL_1H
        __CONFIG    _CONFIG2H, _WDTEN_OFF_2H & _WDPS_512_2H
        __CONFIG    _CONFIG4L, _LVP_OFF_4L
    endasm
    It will use the defaults located in PBP under your chipname.inc


    Then you will get less errors
    I've removed that part of the code together with other modifications but these two errors kip on coming,i dont how to make it work....

    m getting these two assembler errors.
    ERROR"INT_Handler"-Interrupt flag(PIR1,TMR1IF) not found.)
    ERROR"INT_ENABLE"-Interrupt flag(PIR1,TMR1IF) not found.)

    code.
    Code:
    ; i'm using pic16f877
    ;
    define OSC 20
    ;wsave   VAR BYTE    $20     SYSTEM      ' location for W if in bank0
    wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
    wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
     
    ADCON0 = %00000000
    ADCON1 = %00000000  ;all anolog output
    trisb = %11111111   ;define porta as input
    trisc = %11111011   ;make ccp1/portc.2 an output pin
    trisa = %11111111   ;define porta as input
    TMR2 = 16
    PR2 = 34           ;set for 36Khz HPWM(=72 steps*10 times*50hz)        
    CCP1CON = %000001100       ;set to pwm mode
    T2CON=%00000110           ;enable timer2 and set timer2 prescaler value of 1:4
    
    STEPCOUNT var byte
    stepcount = 256
    
    ; Set sine "table" in an array
    sineval var byte[72]
    sineval[1] = 128      ;0 degree
    sineval[2] = 137      ;5 degree
    sineval[3] = 146
    sineval[4] = 154
    sineval[5] = 163
    sineval[6] = 171
    sineval[7] = 179
    sineval[8] = 187
    sineval[9] = 194
    sineval[10] = 200
    sineval[11] = 206
    sineval[12] = 212
    sineval[13] = 216
    sineval[14] = 220
    sineval[15] = 224
    sineval[16] = 227
    sineval[17] = 228
    sineval[18] = 229
    sineval[19] = 230     ;90 degree
    sineval[20] = 229
    sineval[21] = 228
    sineval[22] = 227
    sineval[23] = 224
    sineval[24] = 220
    sineval[25] = 216
    sineval[26] = 212
    sineval[27] = 206
    sineval[28] = 200
    sineval[29] = 194
    sineval[30] = 187
    sineval[31] = 179
    sineval[32] = 171
    sineval[33] = 163
    sineval[34] = 154
    sineval[35] = 146
    sineval[36] = 137
    sineval[37] = 128  ;180 degree
    sineval[38] = 119
    sineval[39] = 110
    sineval[40] = 102
    sineval[41] = 93
    sineval[42] = 85
    sineval[43] = 77
    sineval[44] = 69
    sineval[45] = 62
    sineval[46] = 56
    sineval[47] = 50
    sineval[48] = 44
    sineval[49] = 40
    sineval[50] = 36
    sineval[51] = 32
    sineval[52] = 29
    sineval[53] = 28
    sineval[54] = 26
    sineval[55] = 26
    sineval[56] = 26
    sineval[57] = 28
    sineval[58] = 29
    sineval[59] = 32
    sineval[60] = 36
    sineval[61] = 40
    sineval[62] = 44
    sineval[63] = 50
    sineval[64] = 56
    sineval[65] = 62
    sineval[66] = 69
    sineval[67] = 77
    sineval[68] = 85
    sineval[69] = 93
    sineval[70] = 102
    sineval[71] = 110
    sineval[72] =119
     
    timerone var word 
     
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
     
    ASM
     
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   _sine,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31              
    TMR1L = 255    ; Prescaler = 8, TMR1ON
    TMR1H = 254
    @   INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    timerone = $FD00                ;gives about 50 hz sine 
    Main:
            pause 5
            if timerone = $F9FF then timerone = $FF00
     
    GOTO Main
     
    '---[TMR1_INT - interrupt handler]------------------------------------------
     
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 72
    @    INT_RETURN

  16. #16
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Something is not right. Are you compiling for the right chip, the PIC16F877? Because it does have those registers and bits. Are you using MPASM as your assembler, because the include file requires this. Can you send me your myprogram.lst file? That might tell me more....

  17. #17
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Quote Originally Posted by scalerobotics View Post
    Something is not right. Are you compiling for the right chip, the PIC16F877? Because it does have those registers and bits. Are you using MPASM as your assembler, because the include file requires this. Can you send me your myprogram.lst file? That might tell me more....
    Yes i'm compiling for the PIC16F877 using MPSAM as my assembler

  18. #18
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    I've converted the .lst file into pdf format so that i will be able to attach it,hope it will still serve the purpose.....
    Attached Images Attached Images

  19. #19
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    In fact, your code compiles well over here.

  20. #20
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi, I've been trying to send you the .LST file,but it's bigger than 500000 characters,so i could not upload it on the forum,how should i send it?
    Last edited by Ioannis; - 8th May 2011 at 15:35.

  21. #21
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hmmm. The thing that jumps out at me a bit is that you are using Mpasm v2.30. I think that came out in 1999. Really! I think it is time to upgrade. See if that helps you. You can get the latest one by downloading MPLAB IDE here: http://www.microchip.com/stellent/id...&part=SW007002

  22. #22
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Thanks for the tip....yup,it's it working well now....
    i'm reading the pic16f877 data sheet page 63 about how to change the duty cycle of th pwm,it says the duty cycle is specified by writing to CCPR1L:CCPCON<5:4>. So in our case does this code below specify the duty cycle?if not where the duty cycle of pwm has been specified in the program?i want to know so that i may modify the duty cycle to make it equal to 90%.
    code:
    Code:
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 72
    Last edited by Ioannis; - 8th May 2011 at 15:36.

  23. #23
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Great!

    Yes, that is the duty cycle. Why not modify your array for the 90% instead of doing math here? We want to keep multiplication out of our assembly interrupt handler, otherwise, we will need to change it to a PBP type interrupt. And that would take a lot of time for each interrupt, as it needs to save and restore 70 registers each time it interrupts. If you need it to change dynamically, the beauty of an array rather than a lookup, is that you can change it on the fly (doing math in your main).
    Last edited by ScaleRobotics; - 5th March 2011 at 15:48.

  24. #24
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Thanks, i think i got it...let me experiment with the code i have and see what i got.....
    thank again..
    Last edited by Ioannis; - 8th May 2011 at 15:36.

  25. #25
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    hellow everyone,

    I'm simulating this code on proteus Isis but m not getting the expected waveform(sinusoidal wave form)....the code compiles successful...but the waveform i'm getting getting on the scope is not the one...i need help please..

    Code:
    ;
    define OSC 20
    
    ;*****************VARIABLE DECLARATION******************************************
    wsave   VAR BYTE    $70     SYSTEM      ' alternate save location for W 
    wsave1  VAR BYTE    $A0     SYSTEM      ' location for W if in bank1
    wsave2  VAR BYTE    $120    SYSTEM      ' location for W if in bank2
    wsave3  VAR BYTE    $1A0    SYSTEM      ' location for W if in bank3
    STEPCOUNT var byte                      'Define stepcount as byte type variable
    stepcount = 256
    
    ;**************SETTING THE REGISTERS WITH APPROPIATE BIT DEFINITION************* 
    ADCON0 = %00000000
    ADCON1 = %00000000  ;all anolog output
    trisb = %11111111   ;define porta as input
    trisc = %11111011   ;make ccp1/portc.2 an output pin
    trisa = %11111111   ;define porta as input
    TMR2 = 16
    PR2 = 34           ;set for 36Khz HPWM(=72 steps*10 times*50hz)        
    CCP1CON = %000001100       ;set to pwm mode
    T2CON=%00000110           ;enable timer2 and set timer2 prescaler value of 1:4
    
    ;****************A sine lookup table in an array********************************
    sineval var byte[72]
    sineval[1] = 128      ;0 degree
    sineval[2] = 137      ;5 degree
    sineval[3] = 146
    sineval[4] = 154
    sineval[5] = 163
    sineval[6] = 171
    sineval[7] = 179
    sineval[8] = 187
    sineval[9] = 194
    sineval[10] = 200
    sineval[11] = 206
    sineval[12] = 212
    sineval[13] = 216
    sineval[14] = 220
    sineval[15] = 224
    sineval[16] = 227
    sineval[17] = 228
    sineval[18] = 229
    sineval[19] = 230     ;90 degree
    sineval[20] = 229
    sineval[21] = 228
    sineval[22] = 227
    sineval[23] = 224
    sineval[24] = 220
    sineval[25] = 216
    sineval[26] = 212
    sineval[27] = 206
    sineval[28] = 200
    sineval[29] = 194
    sineval[30] = 187
    sineval[31] = 179
    sineval[32] = 171
    sineval[33] = 163
    sineval[34] = 154
    sineval[35] = 146
    sineval[36] = 137
    sineval[37] = 128  ;180 degree
    sineval[38] = 119
    sineval[39] = 110
    sineval[40] = 102
    sineval[41] = 93
    sineval[42] = 85
    sineval[43] = 77
    sineval[44] = 69
    sineval[45] = 62
    sineval[46] = 56
    sineval[47] = 50
    sineval[48] = 44
    sineval[49] = 40
    sineval[50] = 36
    sineval[51] = 32
    sineval[52] = 29
    sineval[53] = 28
    sineval[54] = 26
    sineval[55] = 26
    sineval[56] = 26
    sineval[57] = 28
    sineval[58] = 29
    sineval[59] = 32
    sineval[60] = 36
    sineval[61] = 40
    sineval[62] = 44
    sineval[63] = 50
    sineval[64] = 56
    sineval[65] = 62
    sineval[66] = 69
    sineval[67] = 77
    sineval[68] = 85
    sineval[69] = 93
    sineval[70] = 102
    sineval[71] = 110
    sineval[72] =119
     
    timerone var word 
     
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    
    ;********Define INT_Handler as ISR********************************************** 
    ASM
     
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   _sine,   ASM,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    T1CON = $31    ; Prescaler = 8, TMR1ON          
    TMR1L = 255    
    TMR1H = 254
    @   INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    timerone = $EE16           ;gives about 50 hz sine 
    Main:
            pause 5
            'if timerone = $F9FF then timerone = $FF00
     
    GOTO Main
     
    '---[TMR1_INT - interrupt handler]------------------------------------------
     
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 72
    @    INT_RETURN
    simulation results attached
    Attached Files Attached Files

  26. #26
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    I don't see any kind of wave form on the scope???

  27. #27
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    sure,it is just a line and not a sine wave form as expected....the simulation log say there are attempts to read unimplemented memory locations being ignored..i dont know what does that mean and if it may be one of the cause...i need help.
    Last edited by Ioannis; - 8th May 2011 at 15:37.

  28. #28
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: Lab X1 and 16F877 examples for beginners

    Hi ! demon
    I want to generator 3 Phase spwm signal for my final year project but I, m started by understanding single phase SPWM by reading the example from
    Microchip appliction notes for sine wave with the 16F series chip..http://ww1.microchip.com/downloads/e...tes/00655a.pdf together with the examples given in http://www.picbasic.co.uk/forum/cont...wave-using-DT- interrupts and http://www.picbasic.co.uk/forum/showthread.php?t=14359.

    there are number of things which i've not understand from these readings and i'm asking for help from anyone who can help me to understand.these things are:
    1)which formular used to generate a lookup table for the sine waveforms
    3)what is the purpose of this piece of code and how to get this values from example of http://www.picbasic.co.uk/forum/cont...-DT-interru and
    TMR2 = 117
    PR2 = 63

    TMR1L = 255
    TMR1H = 254

  29. #29
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default 5KHZsinusoidalPWM

    Hi to every one
    I have worked and modify the code posted by ScaleRobotics and I manage to compile it for the PIC 16F877 and get 2 phase although my output was not very good. my aim is to generate 5kHZ SPWM so that when filtered will give sine waves(50hz). I havebeen reading different application manual and PIC16877 datashet for almost two days but I 'm still in darkness the problem comes for that frequency my duty cycle will have 10bit resolution. here are the questions.

    (1) I Try to write the code to FOR 10 bit resolution to PWM module I dont think if is correct.
    Code:
    TeMP = sineval[STEPCOUNT]
        CCP1CON.4 = Temp.0 ' bit 0
        CCP1CON.5 = Temp.1 ' bit 1       
        CCPR1L = Temp.Byte0 >>2  '
    (2)when I do my calculation
    from microchip application note pwm_frequency=50hz*step*10
    which gives me very low step about 10step which is very low when I try to use it my output become very distorted and only CCP1 gives output while ccp2 dont gives any output.

    any one can help me how to get 5KHZ 36 step and is it nessary to modify my lookup table for 10bit resolution thankx

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts