Jump to content

timer0 (18F452, MIOS 1.9f, asm)


Recommended Posts

hi,

my aim is to create a sort of Fx function for the MIDIBox AY application - following the conception of sound tracker.

the USER_Timer is in use by the SM_DebounceTimer (c64 keyboard / 8x8 sm driver).

so i thought it might be a good idea to work with the timer0

i'm new to timer and interrupt programming. i read some lines about the basic concept of the timer in general but i don't know where to start in the context of MIOS.

basic concept of the Fx function:

[midi event note on] ==> toggle timer0 on

after timer0 cycle 1) Fx 01 write x to reg a

after timer0 cycle 2) Fx 02 write y to reg a

after timer0 cycle 3) Fx 03 write z to reg a

after timer0 cycle 4).Fx 04 write w to reg c

etc.

[midi event note off] ==> toggle timer0 off

so now my question:

1) how to initialize and activate timer0?

2) what is to consider in relation to interrupts?

3) is there already some code with timer0 in action? (where i can learn from)

greetings,

- lemonhorse

Link to comment
Share on other sites

Hi,

the PIC based MIOS doesn't allow you to add interrupt handlers (this has changed in MIOS32)

This means, that the timer overrun flag has to be polled by a routine which is executed periodically (e.g. from the USER_Timer hook, if it is called more often than the target interval of TMR0)

Under http://svnmios.midibox.org/filedetails.php?repname=svn.mios&path=%2Ftrunk%2Fapps%2Fsynthesizers%2Fmidibox_sid_v2%2Fsrc%2Fsid_se.inc

You will find a very simple example - the BPM generator is executed from USER_Timer each mS, but it uses it's own time base TMR0


        ;; check timer0 overrun flag
        BRA_IFCLR INTCON, TMR0IF, ACCESS, SIDSE_Clk_NoInc
        bcf     INTCON, TMR0IF                  ; clear overrun flag
        SET_BSR TIMER0_RELOAD_L
        bcf     T0CON, TMR0ON
        movf    TIMER0_RELOAD_L, W, BANKED      ; (dummy add to update TMR0H, and to get carry flag of addition)
        addwf   TMR0L, W                        ; (update TMR0H)
        movf    TIMER0_RELOAD_H, W, BANKED
        addwfc  TMR0H, F
        movf    TIMER0_RELOAD_L, W, BANKED
        addwf   TMR0L, F                        ; 16bit register update takes place with this write
        bsf     T0CON, TMR0ON
        SET_BSR SID_BASE
SIDSE_Clk_Inc
... your code which will be executed periodically
SIDSE_Clk_NoInc
[/code] TIMER0_RELOAD_[LH] defines the timer interval: 0x10000 - (interval / (2*100 nS)) e.g., a reload value of 0xc000 leads to an interval of 3.277 mS Initialisation in USER_Init:
[code]
       ;; ensure that timer0 interrupt not enabled
        bcf     INTCON, T0IE

        ;; internal clock source, 16bit, prescaler 1:2
        movlw   (1 << TMR0ON)
        movwf   T0CON

Best Regards, Thorsten.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...