sinusoidal PWM


Results 1 to 40 of 84

Thread: sinusoidal PWM

Threaded View

  1. #37
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi to all

    I am here again I am still working on the code I posted last 2 days. It try to work on the code but I still get the same output, as I Attach on the two days ago, when I try to put LED on the interrupt service routine and to see if the frequency is clear this became another problem to me. The problem arising are

    (1) The ouput does not apper smoth and which condition should I put to show I get the desired frequency . I atttach again the output as seen from ISIS and the code use to generate that output.

    Code:
    DEFINE OSC 4
    
    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   ; vakue loaded to TMR1 to 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
    When I start learning timer in the days ago I passed across 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 this formular gives me a small count which I can not use to test the frequency condition.

    thanks
    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