sinusoidal PWM


Results 1 to 40 of 84

Thread: sinusoidal PWM

Threaded View

  1. #36
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi HenrikOlsson
    thankx for your coments and Idea you gave me on the code I posted last time which make my output to be some how clear. But is not quiet clear. here are some challenges I faced again

    (1) The ouput does not apper smoth. I tttach the output as seen from ISIS and code.

    Code:
    STEPCOUNT var byte
    STEPCOUNT1 var byte
    
    STEPCOUNT = 0   'pointer for phase one in sinearray
    STEPCOUNT1 = 12 'pointer for phase two  in sine array
    ADCON0 = %00000000
    ADCON1 = %00000000
    
    TRISB = %11111001
    TRISC = %11111001  'PMW output for CCP1 AND CCP2
    TRISA = %11111111
    TMR2 = 117
    PR2 = 55   'set for 18Khz HPWM
    CCP1CON = %00001100 'set CCP1 for PWM OPERATION
    CCP2CON = %00001100 'set CCP2 for PWM OPERATION
    T2CON = %00000100  'TIMER2ON and prescale of 1:1 
    
    sineval var byte[36]
    sineval[0] = 128   
    sineval[1] = 150   
    sineval[2] = 171
    sineval[3] = 191
    sineval[4] = 209
    sineval[5] = 225
    sineval[6] = 238
    sineval[7] = 247
    sineval[8] = 253
    sineval[9] = 255  
    sineval[10] = 253
    sineval[11] = 247
    sineval[12] = 238   
    sineval[13] = 225
    sineval[14] = 209
    sineval[15] = 191
    sineval[16] = 171
    sineval[17] = 150
    sineval[18] = 128   
    sineval[19] = 105
    sineval[20] = 84
    sineval[21] = 64
    sineval[22] = 46
    sineval[23] = 30
    sineval[24] = 17
    sineval[25] = 8
    sineval[26] = 2
    sineval[27] = 0
    sineval[28] = 2
    sineval[29] = 8
    sineval[30] = 17
    sineval[31] = 30
    sineval[32] = 46
    sineval[33] = 64
    sineval[34] = 84
    sineval[35] = 105
     
     timerone var word 
    Temp var byte
    Temp1 var byte
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System          emp
     
     
    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;1, TMR1 ON
    @   INT_ENABLE  TMR1_INT     ; Enable Timer 1 Interrupts 
    
     
    timerone = 64980   ;gives about 50 htz sine 
    Main:  
    
    PAUSE 5
     GOTO Main
     
    '---[TMR1_INT - interrupt handler]------------------------------------------
    
    sine:
         T1CON = 000000 'stop the timer
    
        TMR1L = timerone.byte0 'reload the timer
        TMR1H = timerone.byte1
        
        
        T1CON = 000001         'start the timer
         
        TeMP = sineval[STEPCOUNT]
        CCP1CON.4 = Temp.0 ' bit 0
        CCP1CON.5 = Temp.1 ' bit 1       
        CCPR1L = Temp >>2  'Bit 2-7 
        
        TeMP1 = sineval[STEPCOUNT1]
        CCP2CON.4 = Temp.0 ' bit 0
        CCP2CON.5 = Temp.1 ' bit 1       
        CCPR2L = Temp >>2  'Bit 2-7 
        stepcount =  stepcount +1
        stepcount1 =  stepcount1 +1    
        if stepcount = 36 then stepcount =0
        if stepcount1 = 36 then stepcount1 =12   
     
    @    INT_RETURN
    (2) I try to write a code so that I can measure if the interrupt frequence is 1800hz.
    When I start learning timer in the previous days I passed I cross the link http://www.microcontrollerboard.com/...-tutorial.html there is formural for calcalating a numeric value(count) to be placed to obtain the desired output frequency.
    count=fclk/(4*prescale*(65536-TMR1)*fout

    where for me
    fout=1800hz, prescale 1, TMRI=64980 and fclk=4MHz

    gives count = 1 ohh! here I'm confusing how should I proceed since is very small count I cant use it.

    can you help which count should I use so I can measure my interrupt frequecy
    thankx
    Attached Files Attached Files

Members who have read this thread : 0

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