DT-ints-18, How to ...


Closed Thread
Results 1 to 19 of 19
  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default DT-ints-18, How to ...

    Good Day to all of you in the forum,

    I will like to have some direction on how to generate an interrupt ( used to call up a subroutine ) every 10 ms.
    I will like to know how to set_up the system to get interrupts at a desired period
    I am using PICbasic pro 2.50 and DT-ints-18. Pic is 18f4523 running at 40 MHz.
    Thanks in advance for any help.
    Ambrogio

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Hi,
    Have you looked at the examples provided by Darrel on his site where you downloaded the DT-Ints files?
    May I suggest you use this one as a starting point. The example lets TMR1 free-run so the interrupt triggers at a given frequency (each time TMR1 overflows).

    To change the frequency you reload the timer with a specific value each interrupt, so that it starts from a value other than zero.

    See if you can get that example to work as is for starters.

    /Henrik.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Hi,

    Steve Monfette ... aka DJ KeeWee ... aka Mr E ...
    published here ( 2004 ) a phase control dimmer project where everything was shown ...

    don't remember if using DT Interrupts ... but working !!!

    the code ...
    http://www.picbasic.ru/_fr/3/LampDim.bas

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Thanks Heirik and Acetronics2.
    I will go on with your indications.
    My antivirus does not allow to me to open the following :
    http://www.picbasic.ru/_fr/3/LampDim.bas
    Any possibility to have the files posted to me ?
    Thanks,
    Ambrogio
    [email protected]

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


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Right click and save as ?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    The problem is that my antivirus does not allow me to enter that link.
    Thanks
    Ambrogio

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


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Will this work for you?

    LampDim.bas
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    I have loaded the program as indicated .
    No errors displayed.
    I am using pbp 2.50, picf184523 @ 40 MHz speed.
    I have a square wave output at porta.4 and 100 msec period ( 50 msec high and 50 msec low ).
    Where does the 100 msec come from ?
    How could I set different periods ?
    The program is attached here.
    Thanks
    Ambrogio

    'HSPLL OSCILLATOR HAS BEEN DEFINED IN THE PBP FOLDER > 18F4523 FILE

    DEFINE OSC 40
    LED1 VAR PORTA.4
    INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON = $31 ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    Main:
    PAUSE 1
    GOTO Main

    '---[TMR1 - interrupt handler]--------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    @ INT_RETURN

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


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    >Where does the 100 msec come from ?

    It comes from the formula ...
    1/(OSC * 1000000 / 4 / Prescaler / 65536)
    1/(40 * 1000000 / 4 / 8 / 65536) = 0.0524 Sec. = 52.4 mS
    Times 2 for a full cycle = 104.8 mS

    >How could I set different periods ?

    If the frequency is fixed, use the Timer Template ...
    http://darreltaylor.com/DT_INTS-14/TimerTemplate.html
    DT

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Do we just change these to their 18F counterparts for 18F PICs?

    INCLUDE "DT_INTS-14.bas"
    INCLUDE "ReEnterPBP.bas'
    Robert

  11. #11
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Thanks Darrel for the assistance.
    I red the pic18f4523 spec and I am just a little bit confused on how write and read the timer1 counter that is 16 bit long.
    What is the picbasic code to read and write that 16 bit timer/counter ?
    Your responses are always sharp an relly effective: congratulation.
    Best regards,
    Ambrogio
    IW2FVO

  12. #12
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    IW2FVO,
    To read the timer:

    variable var word
    variable = tmr1

    To write the timer:
    tmr1 = variable

    Its just that simple....
    Dave Purola,
    N8NTA
    EN82fn

  13. #13
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    thanks,
    if I write tmr1= 64 then the compiler gives me :
    >> error 113..... pbpp18.lib580 : symbol not previously defined (tmr1 ) and then the same message but lib588, lib927, lib 933.
    So the point is still : how to read / write TMR1 ?
    Any help is appreciated.
    Thanks
    Ambrogio

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,601


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Is post #10 above the issue?

    Robert

  15. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Hi,
    It's easy but I'm afraid it's not THAT easy - there is no TMR1 register (hence the error). Instead TMR1 consists of TWO 8bit regsiters, TMR1L and TMR1H.

    The straight forward way to write it is to do
    Code:
    TMR1L = 0
    TMR1H = 0
    And the straight forward way to read it is
    Code:
    myVar VAR WORD
    myVAR.HighByte = TMR1H
    myVAR.LowByte = TMR1L
    When reading TMR1 this way there's a slight posibillity that TMR1L overflows right in between reading TMR1H and TMR1L giving you a wrong result. To prevent that the easiest way is to simply STOP the timer before reading it. If that's not possible there are other ways to cater for that - and there are tricks that allows you to read it in one go if needed but lets keep it as simple as possible for now.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    If you are using the Timer Template, then there's no reason to read or write to the Timer directly. It is handled for you by the template.

    If you are not using the template, you should at least use the Timer Reload routine from the template.
    To maintain a constant frequency that also accounts for interrupt latency, the reload value must be ADDED to the current value in the Timer.

    Just reloading a value into the Timer will give a frequency output, but accuracy and consistency will suffer.

    There are other ways to ADD the reload value to the Timer, but you must know exactly how many instructions it takes to do the addition.
    The routine in the template is already known to take 8 instruction cycles.
    The template automatically adjusts for that amount of time.

    With the template, if you tell it you want 100hz ... you get 100.0 Hz.

    With all of that said ... you still haven't revealed whether you want a Fixed frequency or Variable frequencies?
    It makes a huge difference.
    DT

  17. #17
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Thanks to everybody for the assistance.
    yes, I need a fixed frequency so I can use the timer tamplate. >> Is this table applicable to pic18f4523 ?
    Additional question:
    >> what is the purpose of bit_7 ( rd16 ) in the t1con register? How to use it ?
    >> what is the purpose odf the RESETFLAG? yes/no in the DT _int ?
    Regards,
    Ambrogio

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


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    The table is applicable to all PIC's, but it doesn't include the higher OSC frequencies of the 18F's.

    If your interrupt frequency is greater than 160 Hz (80 Hz Full Cycle), you don't need to worry about the table.
    Just set Prescaler to 1 and Freq to your frequency.

    The RD16 bit buffers the highbyte of the Timer so that both bytes can be read or written without stopping the Timer.
    The Timer Template will not work with RD16 set.

    With interrupts that require you to manually clear the interrupt flag, setting RESETFLAG to YES will allow DT_INTS to clear it for you.
    DT

  19. #19
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT-ints-18, How to ...

    Thanks again Darrel for the great assistance.
    regards,
    Ambrogio
    IW2FVO
    North Italy

Similar Threads

  1. DT INTs which int to use??
    By Heckler in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th March 2012, 00:23
  2. out of memory using DT-ints-14 and 16F610
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th January 2011, 03:30
  3. DT-INTs Blinky Light question
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th February 2010, 03:29
  4. Problem with Dt Ints Interrupts
    By Quin in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th July 2008, 19:21
  5. DT-ints-18 - new version
    By dip1 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 10th October 2007, 20:09

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