ProblemwithPWMfrequency


Results 1 to 38 of 38

Threaded View

  1. #9
    Join Date
    Oct 2011
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: ProblemwithPWMfrequency

    Thankx HenrikOlsson for the comments I worked on on them

    For what I know the gosub coment within subroutine takes two return. The first return will bring you back to the subroutine(TEST) and the second return will bring you to the original gosub comand if I'm not wrong.

    I havebeen worked on the code for almost whole day I'm still getting the same output and I try know my interrupt frequency by Toggling PortB.1 the problem comes I cant see the square wave comes from that pin. here is code and output from ISIS.

    Code:
    define OSC 4
    Wsave var byte   $70system
    Wsave1 var byte  $A0system
    Wsave2 var byte  $120system
    Wsave3 var byte  $1A0system
    ADCON0 = %00000000
    ADCON1 = %00000000
    LED1   VAR  PORTB.1
    
    TRISB = %11111101
    TRISC = %11111001  'PMW output for CCP1 AND CCP2
    TRISA = %11111111
    PR2 =  199   'set for 5Khz HPWM
    CCP1CON = %00001100 'set CCP1 for PWM OPERATION
    CCP2CON = %00001100 'set CCP2 for PWM OPERATION
    T2CON = %00000100  'TIMER2ON and prescale of 1:1 
    index var byte
    temp var word
    timerone var word 
    INCLUDE "DT_INTS-14.bas"     ; Base Interrupt System          
    INCLUDE "ReEnterPBP.bas"  
    ASM
     
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,   _TEST,  PBP,  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
    
    TEST: 
        T1CON = 000000 'stop the timer
        TMR1L = timerone.byte0  'reload the timer
        TMR1H = timerone.byte1
        T1CON = 000001          ' start the timer
        gosub display
        CCP1CON.4 = Temp.0 ' bit 0
        CCP1CON.5 = Temp.1 ' bit 1       
        CCPR1L = Temp>>2  'Bit 2-7
        TOGGLE LED1  
        index=index+1
      if index =36 then index =0
       
         
     @    INT_RETURN
     
     display:
      lookup index,[115,102,90,79,70,62,57,53,52,53,57,62,70,79,90,102,115,128,141,154,166,177,186,194,199,203,204,203,199,194,186,177,166,154,141,128],temp
        
      return    'return to the subroutine 
      return    'return to the original GOSUB
    I don't understand why the output is 2.5Kh instead of 5khz

    help me on that problems
    thankx
    Attached Images Attached Images

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