lemonhorse Posted April 8, 2009 Report Share Posted April 8, 2009 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 timer0i'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 onafter timer0 cycle 1) Fx 01 write x to reg a after timer0 cycle 2) Fx 02 write y to reg aafter timer0 cycle 3) Fx 03 write z to reg aafter timer0 cycle 4).Fx 04 write w to reg cetc.[midi event note off] ==> toggle timer0 offso 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 Quote Link to comment Share on other sites More sharing options...
TK. Posted April 8, 2009 Report Share Posted April 8, 2009 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.incYou 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_BASESIDSE_Clk_Inc... your code which will be executed periodicallySIDSE_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 T0CONBest Regards, Thorsten. Quote Link to comment Share on other sites More sharing options...
lemonhorse Posted April 8, 2009 Author Report Share Posted April 8, 2009 thanks TK,now i got stuff for experimentation! :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.