sinusoidal PWM


Closed Thread
Results 1 to 40 of 84

Thread: sinusoidal PWM

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    i have changed the number of array size together with other modifications but there is no change in the simulation result,it is still a line....
    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[73]
    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 = 1 then stepcount = 73
    @    INT_RETURN
    Last edited by Ioannis; - 8th May 2011 at 15:37.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    First thing I would do is make sure the ISR is working. Make an unused pin an output, then toggle it in the ISR. hook a scope to that and make sure it toggles. Also you can do the same in your main with another pin.

    This way you will know some basic info like is my pic running, is my interrupt firing. do that and report back
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    hi,
    i've managed to get the sinusoidal output sine wave although i'm getting frequency of 202Hz instead of 50Hz and peak voltage of 4.58v instead of 4.5v.Also the waveform is not smooth.Simulation results.docWhat should i do to acheave this parameters?
    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 
    ADCON0 = %00000000
    ADCON1 = %00000000
    trisb = %11111111
    trisc = %11111011
    trisa = %11111111
    TMR2 = 16
    PR2 = 15      ;set for 16Khz HPWM        
    CCP1CON.3 = 1        ' set to pwm mode
    CCP1CON.2 = 1
    T2CON.2=1
    T2CON.0=1
    STEPCOUNT var byte
    stepcount = 32
    ; 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
    sineval[6] = 213
    sineval[7] = 222
    sineval[8] = 228
    sineval[9] = 230
    sineval[10] = 228
    sineval[11] = 222
    sineval[12] = 213
    sineval[13] = 200
    sineval[14] = 185
    sineval[15] = 167
    sineval[16] = 148
    sineval[17] = 128
    sineval[18] = 108
    sineval[19] = 89
    sineval[20] = 71
    sineval[21] = 56
    sineval[22] = 43
    sineval[23] = 34
    sineval[24] = 28
    sineval[25] = 26
    sineval[26] = 28
    sineval[27] = 34
    sineval[28] = 43
    sineval[29] = 56
    sineval[30] = 71
    sineval[31] = 89
    sineval[32] = 108
     
     
    timerone var word 
     
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System
    ;include "ReEnterPBP-18.bas"  ;not needed for ASM type interrupt service routines
     
    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 = 65504               ;gives about 50 htz sine 
    Main:
            pause 5
            'timerone = timerone - 1      'uncomment to vary 60hz sine
            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 = 32
     
    @    INT_RETURN

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi,
    You're still off on the array.
    Code:
    Sinval VAR BYTE[32]
    This creates an array of 32 elements numbered 0-31 but you assign values to it starting at 1 and ending at 32 - not very good. There is no SineVal[32], when you read/write to that variable you're actually accessing the "next" RAM location, something I'm sure you don't want to do here.

    You can adjust the peak value by "scaling" the value in your sine-table but really, you're not even 2% off target.

    Are you using a 4MHz x-tal like the code says or are you using something else?

    If I'm not mistaken a reload value of 65505 with a prescaler of 1:8 running at 4Mhz gives an interrupt frequency of 4032Hz, you have 32 "steps" to your cycle so you "should" get around 126Hz....

    For accuracy it's usually better to stop the timer and then ADD the preload value to the timers current value since this will take into account the interrupt latency etc. Stop it, copy it to a WORD, add the reload value, copy it back and restart the timer.

    Any specific reason you're using a TMR1 prescaler of 8? Using a lower prescaler ratio will give you better "resolution" on the interrupt frequency.

    /Henrik.

  5. #5
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    hellow Henrik,
    thanx for the tips, i've re-worked my sine table,also i've include the code for accuracy although i'm not sure if i've place it in a right place!
    For a 4MHz xtal and TMR1 prescaler of 1 i reload the T1 with the value 64980 to get 50Hz and it's what m getting on the scope.
    Also TMR2 with prescaler of 4 is loaded with 117 for the interrupt to be generated every 556us(256-(556/(4*0.25*4))
    But the problem is that the waveform i'm getting on the scope is not smooth at all....Simulation results..pdf

    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 = 13          ;set for 18Khz HPWM(=36 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[36]
    sineval[0] = 128
    sineval[1] = 148
    sineval[2] = 167
    sineval[3] = 185
    sineval[4] = 201
    sineval[5] = 215
    sineval[6] = 227
    sineval[7] = 235
    sineval[8] = 240
    sineval[9] = 242
    sineval[10] = 240
    sineval[11] = 235
    sineval[12] = 227
    sineval[13] = 215
    sineval[14] = 201
    sineval[15] = 185
    sineval[16] = 167
    sineval[17] = 148
    sineval[18] = 128
    sineval[19] = 108
    sineval[20] = 89
    sineval[21] = 71
    sineval[22] = 55
    sineval[23] = 41
    sineval[24] = 29
    sineval[25] = 21
    sineval[26] = 16
    sineval[27] = 14
    sineval[28] = 16
    sineval[29] = 21
    sineval[30] = 29
    sineval[31] = 41
    sineval[32] = 55
    sineval[33] = 71
    sineval[34] = 89
    sineval[35] = 108
     
    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 = %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]------------------------------------------
     
    'accuracy thing
    TimerShadow VAR WORD
    T1CON.0 = 0  'Stop TMR1
    TimerShadow.HighByte = TMR1H
    TimerShadow.LowByte = TMR1L
    TimerShadow = TimerShadow + Timerone
    TMR1H = TimerShadow.HighByte
    TMR1L = TimerShadow.LowByte
    T1CON.0 = 1  'Restart TMR1
    sine:
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 36
    @    INT_RETURN
    where i'm wrong in the code? are the calculations above correct?
    Last edited by Ioannis; - 8th May 2011 at 15:38.

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


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    What are you using for a filter? You should have at least half of the below example to smooth out the signal. Also, it will never look too good on simulation. Might look better on actual hardware. Might be some issues with running it at 4 mhz. Is there a reason you don't want 20 mhz? Even AN655 's example showed 20 mhz.

    Code:
    ;   Filter Diagram
    ;        
    ;               2.7k            2.7k    
    ;    RC2  ___/\  /\  /\______/\  /\  /\________ Analog Output
    ;              \/  \/    |     \/  \/     |  
    ;                        |                |
    ;                      ----- 0.1uF      ----- 0.1uF
    ;                      -----            -----
    ;                        |                |
    ;                       GND              GND
    ;
    ;

  7. #7
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    the 877 pic on the board i'm using have 4Mhz clock, and i'm using the same filter as above.are the calculations above correct?
    Last edited by Ioannis; - 8th May 2011 at 15:38.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi,
    Several things.....
    TMR2 is the timer used for the PWM generation. The fact that you initially load it with 117 doesn't matter for either the PWM frequency or your interrupt frequency since you're using TMR1 to generate the interrupts.

    You have the prescaler for TMR2 set to 1:4 and PR2 set to 13 which indeed gives you ~18kHz PWM frequency but it'll only give you a give you 56 discrete dutycycles. Ie. the maximum value you can put in the dutycycle register is 56. The highest value in your sine table is 242 which you then shift right one time bofore putting in the CCP1L, so you're trying to put 121 in there when 56 is max.

    Changing the prescaler to 1:1 and putting 55 in PR2 gives you the same PWM frequency but allows dutycycle values of 0-222.

    TMR1 is now setup with a prescaler of 1:1 and you reload it with 64980 making it interrupt every 65536-64980=556us or at a frequency of 1798Hz, there's now 36 steps to your "cycle" so 1798/36=49.96Hz so it seems to be correct. I don't think you should expect to be able to run much faster than that at 4Mhz, the DT-ints takes quite afew cycles to save and restore all the system variables on each interrupt so you won't have much time left.

    The "accuracy thing" needs to be performed on each reload or it won't have much effect. It should be in your ISR instead of the reload code you have there now.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi Henrik! As always, great post!
    I've done some work with DT_INTS, and in ASM mode, they are fairly fast, as they only copy a few registers, vs the PBP type, which copies then restores about 70 registers with each interrupt. So I don't understand your warning about going above 4 Mhz? I've run it at 40 Mhz on a different chip and it worked pretty well using ASM type DT_INTS.

  10. #10
    Join Date
    Feb 2011
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Several things.....
    TMR2 is the timer used for the PWM generation. The fact that you initially load it with 117 doesn't matter for either the PWM frequency or your interrupt frequency since you're using TMR1 to generate the interrupts.

    You have the prescaler for TMR2 set to 1:4 and PR2 set to 13 which indeed gives you ~18kHz PWM frequency but it'll only give you a give you 56 discrete dutycycles. Ie. the maximum value you can put in the dutycycle register is 56. The highest value in your sine table is 242 which you then shift right one time bofore putting in the CCP1L, so you're trying to put 121 in there when 56 is max.

    Changing the prescaler to 1:1 and putting 55 in PR2 gives you the same PWM frequency but allows dutycycle values of 0-222.

    TMR1 is now setup with a prescaler of 1:1 and you reload it with 64980 making it interrupt every 65536-64980=556us or at a frequency of 1798Hz, there's now 36 steps to your "cycle" so 1798/36=49.96Hz so it seems to be correct. I don't think you should expect to be able to run much faster than that at 4Mhz, the DT-ints takes quite afew cycles to save and restore all the system variables on each interrupt so you won't have much time left.

    The "accuracy thing" needs to be performed on each reload or it won't have much effect. It should be in your ISR instead of the reload code you have there now.

    /Henrik.
    i've the changes in the code as you suggested above,but the waveform is still not smooth....Simulation results..pdf

    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] = 128
    sineval[1] = 148
    sineval[2] = 167
    sineval[3] = 185
    sineval[4] = 201
    sineval[5] = 215
    sineval[6] = 227
    sineval[7] = 235
    sineval[8] = 240
    sineval[9] = 242
    sineval[10] = 240
    sineval[11] = 235
    sineval[12] = 227
    sineval[13] = 215
    sineval[14] = 201
    sineval[15] = 185
    sineval[16] = 167
    sineval[17] = 148
    sineval[18] = 128
    sineval[19] = 108
    sineval[20] = 89
    sineval[21] = 71
    sineval[22] = 55
    sineval[23] = 41
    sineval[24] = 29
    sineval[25] = 21
    sineval[26] = 16
    sineval[27] = 14
    sineval[28] = 16
    sineval[29] = 21
    sineval[30] = 29
    sineval[31] = 41
    sineval[32] = 55
    sineval[33] = 71
    sineval[34] = 89
    sineval[35] = 108
     
    timerone var word 
    TimerShadow 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 = %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:
    'accuracy thing
    T1CON.0 = 0  'Stop TMR1
    TimerShadow.HighByte = TMR1H
    TimerShadow.LowByte = TMR1L
    TimerShadow = TimerShadow + Timerone
    TMR1H = TimerShadow.HighByte
    TMR1L = TimerShadow.LowByte
    T1CON.0 = 1  'Restart TMR1
    
        TMR1L = timerone.byte0
        TMR1H = timerone.byte1     
        CCPR1L = sineval[STEPCOUNT]>>1 
        stepcount = stepcount -1
        if stepcount = 0 then stepcount = 36
    
    @    INT_RETURN

  11. #11
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Check into Don Lancaster's Magic Sinewaves here: http://www.tinaja.com/
    I did it with a basic stamp BS1 several years ago when I was a newby, it is quite simple and works great.

  12. #12
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: sinusoidal PWM

    Hi!

    I manage to compile and modify the example from that link www.picbasic.co.uk/forum/cont...-DT-interrupts, for pic 16877. Because the pic I want to use for three phase spwm signal is (16f777) which has 3 CCP module and I' m waiting for it to come the problem it is not includeded in ISIS simulator that is why I used pic 168777 having 2 CCP module for simulation and is present in ISIS and my college lab. I belive if I manage to generate two phase spwm it became eaasy for 3 phase spmw.

    here is the code and attachement of my output from ISIS and mysinelooktable and
    define OSC 4

    STEPCOUNT var byte
    STEPCOUNT1 var byte
    STEPCOUNT = 0 'pointer for phase one in sinearray
    STEPCOUNT1 = 0 'pointer for phase two in sine array
    ADCON0 = %00000000
    ADCON1 = %00000000

    TRISB = %11111111
    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
    TMR1L = 255
    TMR1H = 254
    @ 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:
    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

    TeMP1 = sineval[STEPCOUNT1]
    CCP2CON.4 = Temp.0 ' bit 0
    CCP2CON.5 = Temp.1 ' bit 1
    CCPR2L = Temp >>2 'Bit 2-7
    if stepcount = 36 then stepcount =0
    if stepcount1 = 24 then stepcount1 =0
    stepcount = stepcount +1
    stepcount = stepcount1 +1

    @ INT_RETURN



    any one can help me
    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