Changing the sines frequency?


Results 1 to 33 of 33

Threaded View

  1. #13


    Did you find this post helpful? Yes | No

    Default Re: Changing the sines frequency?

    Quote Originally Posted by HenrikOlsson View Post
    Yes, but you still need to keep the reloading code in the interrupt routine otherwise the timer will "freewheel" again.

    In your code, as the very first thing in the ISR, you are currently overwriting the TMR1 register with the value of a variable called timer.
    Code:
    ' PWM calculation and update interrupt (Timer 1) 
    pwmint:
     
    ' Timer 1 update
    TMR1L=timer.lowbyte     '<---This is overwriting the TMR1 registers!
    TMR1H=timer.highbyte
    So, once the code gets to "copying" the TMR1 registers and adding the reload value to it you have overwritten it with something else.

    I've just tested the following code here:
    Code:
    DEFINE LOADER_USED 1
    DEFINE OSC 20
     
    INCLUDE "DT_INTS-18.bas"
    INCLUDE "ReEnterPBP-18.bas"
    INCLUDE "IncPID.pbp"
     
    TMRCopy VAR WORD
    TimerReloadValue VAR WORD
    TimerReloadValue = 63000
     
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler   TMR1_INT,  _TimezUp,   PBP,  yes
        endm
        INT_CREATE              ; Creates the interrupt processor
    ENDASM
     
    @ INT_ENABLE  TMR1_INT      ; enable Timer 1 interrupts
     
    TRISB.0 = 1                 ' +button
    TRISA.4 = 1                 ' -button
    TRISB.3 = 0                 ' Output to measure interrupt frequency 
     
    CMCON = 7
    ADCON1 = %00001111          ' No analog inputs.
    T1CON.0 = 1                 ' Start TMR1
     
    Main:
    If PortB.0 = 0 then
      TimerReloadValue = TimerReloadValue + 1
      LCDOUT $FE,1,#TimerReloadValue
    ENDIF
    If PortA.4 = 0 then
      TimerReloadValue = TimerReloadValue - 1
      LCDOUT $FE,1,#TimerReloadValue
    ENDIF
    Pause 20
    Goto Main
     
    ' ---------- Interrupt handler ------------
    TimezUp:
      T1CON.0 = 0                             ' Stop TMR1
      TMRCopy.HighByte = TMR1H                ' Copy value of TMR1 registers
      TMRCopy.LowByte = TMR1L 
      TMRCopy = TMRCopy + TimerReloadValue    ' Add reload value (compensates for overhead)
      TMR1H = TMRCOPY.HighByte                ' And back to TMR1
      TMR1L = TMRCopy.LowByte
      T1CON.0 = 1                             ' Restart Timer
    Toggle PortB.3
    @ INT_RETURN
    And it works fine. Pushing the buttons connected to PortB.0 and PortA.4 increases/decreases the reload value for the timer and the interrupt frequency.

    But, again, a change of 1 at the "top" will not result in the same change in interrupt frequency as a change of 1 at the "botton".
    Tried this in my code with the sines, it works.

    Code:
    But, again, a change of 1 at the "top" will not result in the same change in interrupt frequency as a change of 1 at the "botton".
    So what the point since the first program? It is impossible to change proportionally this interrupt frequency in run time? Or any math relation/equation to calculate the correct timer value according to the desired frequency?

    Like you said, I can make a lookup table, but this program is intended to make a 3-phase VFD AC motor drive, adjustable from 0 to 120Hz with 0.1Hz increments... so if I use a lookup table, it will take 1200 variables! Doesn't sure that my PIC had enough memory capacity...
    And how to calculate the "correct preload value"?
    Last edited by pxidr84; - 6th March 2011 at 21:27.

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