sinusoidal PWM


Closed Thread
Results 1 to 40 of 84

Thread: sinusoidal PWM

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Previously you started at the "end" of table and decremented the "pointer" but now you've apparently changed that so it starts at 0 and increments the pointer instead.

    If you want it phase shifted 180° ("inverted") then simply "reverse" your sin-table. 128, 108, 89, 71.... instead of 148, 167, 185....

  2. #2
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    hellow,

    i've managed to generate SPWM signal using 4MHz xtal ,thanx to Henrik for the tip of modifying the lookup table values,this is the screen shoot taken from the actual scope.....Name:  0000.JPG
Views: 15028
Size:  143.3 KB

    however,there are things i'm not happy with this signal...
    1)i expected to see at least one complete cycle on the screen for a single screen shoot,but this is not the case,it is either positive or negative cycle!what should i do?

    2)in theory,SPWM signal is obtained by comparing the triangular wave having a certain switching frequency with a sine wave of certain modulating frequency (50Hz for my case),now the HPWM frequency is 18KHz,is this the switching frequency?if not how do i know the switching frequency for this kind of generation?i want a switching frequency around 2KHz. i want to use this signal to control a single phase inverter.

    here is my code:
    Code:
    define OSC 4
    
    ;*****************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 = 36
    
    ;**************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 = 117
    PR2 = 55          ;set for 18Khz HPWM(=36 steps*10 times*50hz)        
    CCP1CON = %000001100       ;set to pwm mode
    T2CON=%00000100           ;enable timer2 and set timer2 prescaler value of 1:1
    
    ;****************A sine lookup table in an array********************************
    sineval var byte[36]
    sineval[0] = 115
    sineval[1] = 102
    sineval[2] = 90
    sineval[3] = 79
    sineval[4] = 70
    sineval[5] = 62
    sineval[6] = 57
    sineval[7] = 53
    sineval[8] = 52
    sineval[9] = 53
    sineval[10] = 57
    sineval[11] = 62
    sineval[12] = 70
    sineval[13] = 74
    sineval[14] = 90
    sineval[15] = 102
    sineval[16] = 115
    sineval[17] = 128
    sineval[18] = 141
    sineval[19] = 154
    sineval[20] = 166
    sineval[21] = 177
    sineval[22] = 186
    sineval[23] = 194
    sineval[24] = 199
    sineval[25] = 203
    sineval[26] = 204
    sineval[27] = 203
    sineval[28] = 199
    sineval[29] = 194
    sineval[30] = 186
    sineval[31] = 177
    sineval[32] = 166
    sineval[33] = 154
    sineval[34] = 141
    sineval[35] = 128
     
    timerone var word 
    Temp VAR byte 
    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 = %000001    ; Prescaler = 1, TMR1ON          
    TMR1L = 255    
    TMR1H = 254
    @   INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts  
    timerone = 64980          ;gives about 50 hz sine 
    Main:
            pause 5
            
    GOTO Main
     
    '---[TMR1_INT - interrupt handler]------------------------------------------
    
    
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        Temp = SineVal[StepCount]   
        CCP1CON.4 = Temp.0   'Bit 0
        CCP1CON.5 = Temp.1   'Bit 1
        CCPR1L = Temp >> 2     'Bit 2-7
        if stepcount = 0 then stepcount = 36 
        stepcount = stepcount -1
       
    
    @    INT_RETURN

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi,
    1)i expected to see at least one complete cycle on the screen for a single screen shoot,but this is not the case,it is either positive or negative cycle!what should i do?
    I haven't checked your code but going by the comments you expect a 50Hz "sinewave", a full period at 50Hz is 20ms but your scope is set to 200us/div, there's 10 divisions so you're only displaying 2ms on the screen. I see a 10:1 note there but does that apply to the horizontal sweep?

    I don't understand the part with the triangular wave being compared with a sine etc but the switching frewuency IS the PWM frequency, or 18kHz in this case. If you want 2kHz you need to reconfigure the PWM module to output 2kHz which might also require adjusting the sine-table depending on how the numbers play out.

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