dt int timer1 ignores offset value


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42

    Default dt int timer1 ignores offset value

    hi everyone. im trying to produce a sine wave with this section of code, on a 18f2431
    Code:
    INTCON = %11000000
    T1CON = %10000001
     TIMER = 64233
         TIMER.BYTE0 = TMR1L ;= $E9
         TIMER.BYTE1 = TMR1H ;= $FA
      INCLUDE "DT_INTS-18.bas"
    ;----[High Priority Interrupts]-----------------------------------------------
    ASM
    INT_LIST  macro    ; IntSource,   Label,  Type,  ResetFlag? 
            INT_Handler   TMR1_INT,   _SINE,   asm,  yes
            
        endm
        INT_CREATE
         
        INT_ENABLE TMR1_INT
                                            
    ENDASM
    
    
    SINE:
    PORTA.1 = 1
    X = X + 1
    IF X > 63 THEN X = 0
    LOOKUP X,[127, 139, 152, 164, 176, 187, 198, 208, 217, 225, 233, 239, 244, 249, 252,_
              253, 254, 253, 252, 249, 244, 239, 233, 225, 217, 208, 198, 187, 176, 164,_
              152, 139, 127, 115, 102, 90, 78, 67, 56, 46, 37, 29, 21, 15, 10, 5, 2, 1,_
              0, 1, 2, 5, 10, 15, 21, 29, 37, 46, 56, 67, 78, 90, 102, 115],SINEWAVE
    
         
    PORTA.1 = 0
         
    @  INT_RETURN
    timer1 works to the preload value, but completely ignores my offset values.
    yes, i checked all over the forum, and the solutions suggested was to use timer0. i really need to use this timer, because of its high resolution, and the other timers will be tied up in later programming stages. ive tried all this:
    Code:
    TIMER = 64233
         TIMER.BYTE0 = TMR1L
         TIMER.BYTE1 = TMR1H
    and
    Code:
    TMR1L = $E9
    TMR1H = $FA
    what i'm doing wrong?
    NAG CON WIFE!
    WIFE VAR MOOD

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Timer1 should be re-loaded each time in the handler.
    It should be the first thing done in the handler, and it should be added to the timer value instead of just loaded.
    Adding the value helps to compensate for interrupt latencies, keeping the frequency nice and stable.

    To make it easier to add, RD16 (T1CON.7) should be turned off.

    Code:
    Timer1  VAR WORD EXT
    @Timer1 = TMR1L
    
    T1CON = %00000001
    TIMER = 64233
    
    ;... Main program here
    
    SINE:                      ; interrupt handler
        T1CON.0 = 0            ; stop Timer
        Timer1 = Timer1 + TIMER
        T1CON.0 = 1            ; restart Timer
    
    ;... rest of handler
    @ INT_RETURN
    DT

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Not 100% sure what you mean but I think you're forgetting to reload the timer inside the ISR.

    If you preset the timer to 12345 at the beginning of the program you'll interrupt after 65536-12345 cycles - the first time only. Then the timer will be free running and you'll get an interrupt every 65536th cycle (1:1 prescaler).

    Or is that not at all what you're asking about?

    /Henrik.

    EDIT: Oh, well the man himself beat me to it - again.... ;-)

  4. #4
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default thanks for the reply.

    thanks for coming to my aid, guys. reload the value within the isr. now i know. the timer is working, with the offset with a new problem; im aiming for 3840 hz, and thats = 64233 offset value.
    instead, im getting 3030 hz. i used a different pic timer calculator because picmulticalc will not run in windows 7.
    this is not really a big problem, as i can adjust the offset value to get the exact frequency that im aiming for.

    Timer1 VAR WORD EXT ; what does the EXT stand for?

    thanks
    NAG CON WIFE!
    WIFE VAR MOOD

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DDDvvv View Post
    im aiming for 3840 hz, and thats = 64233 offset value.
    instead, im getting 3030 hz.
    What OSC are you running at?

    64233 would be close for 20Mhz.
    With 16Mhz OSC it would give 3.06 Khz.

    picmulticalc will not run in windows 7
    Turn on XP compatability mode for PicMultiCalc.

    Timer1 VAR WORD EXT ; what does the EXT stand for?
    The EXT (external) modifier.
    http://www.picbasic.co.uk/forum/showthread.php?t=3891

    Scroll down to ... Using EXT with Variables.
    DT

  6. #6
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Smile

    thanks again for the reply. yes, i have the osc set for 16 mhz. there's my problem!

    about picmulticalc, it starts ok in windows 7 but when you click on any of the buttons (timer calc, timer helper, usart calc) i get a runtime error 713; missing msstdfmt.dll that needs to be installed. rather than troll the web searching for a "trojaned" file, i chose a different calc.

    thanks
    NAG CON WIFE!
    WIFE VAR MOOD

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,517


    Did you find this post helpful? Yes | No

    Default

    Hi,
    FYI, I run PICMultiCalc on Win7-64bit without any problems, no compatibility mode set or anything.

    /Henrik.

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    FYI, I run PICMultiCalc on Win7-64bit without any problems, no compatibility mode set or anything.

    /Henrik.
    Me too. And I can not find msstdfmt.dll on my machine??
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    im using 32 bit windows 7. maybe thats the prob..
    NAG CON WIFE!
    WIFE VAR MOOD

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I also have win7 32 bit and no problems there either.
    Maybe you have a bad copy of multicalc?

    When I get back to the shop later to day I will upload the copy I have.
    Dave
    Always wear safety glasses while programming.

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    DDDvvv,
    You can go here to get the version of MultiCalc that I have. Not sure if there is more than on version... This one works on win7, both 32 and 64 bit machines.
    http://mackrackit.cambs.net/files/

    Just saw your article on driving a stepper in hardware mode, missed that thread.
    Cool project!!! Now something else to play with that I do not have time for...
    Thanks!!!
    Dave
    Always wear safety glasses while programming.

  12. #12
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    That's a really old version Dave.

    Here's the latest ... v1.3.1
    http://www.picbasic.co.uk/forum/cont....-PICMultiCalc
    DT

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    WOW! I have an antique!!! Custom Character generator on the new one too!!!
    I really need to get out more...
    Thanks Darrel!

    The new one works for me on win7, 32 and 64 bit machines with the exception of the custom character generator on the 64 bit. Says I am missing FM20.DLL.
    Here is what Micro Soft says about it, but I did not try their solution.
    http://support.microsoft.com/kb/214757
    Why the 32 bit machine is "OK" with it is a mystery to me. I have Micro Soft Security Essentials and auto updates turned on for both machines.
    Dave
    Always wear safety glasses while programming.

  14. #14
    Join Date
    Dec 2009
    Location
    Kalamazoo
    Posts
    42


    Did you find this post helpful? Yes | No

    Default

    thanks for all the replies. i got both picmulticalc, 1.0.0 and 1.3.1 , and i still get the same missing file error. im thinking that it has something to do with the windows 7 version that im using. (upgraded from winxp running on an old computer)

    i have a winxp notebook that runs the calc perfectly, so im using that for now. thanks for the help.

    mr mackrackit, yes, the stepper project was interesting. i should have named it "hardware pwm stepper drive" . however, i did not put alot of r&d on that project because of two reasons: i moved on to servo dc motor control, and i use the sla 7078 stepper driver for all my stepper interfacing. hopefully, someone improves it to something practical.
    NAG CON WIFE!
    WIFE VAR MOOD

  15. #15
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    hopefully, someone improves it to something practical.
    I am sure someone will benefit from it. Thanks again for sharing.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

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