Hi,
There is no interrupt in my program, since using DT-Ints have been covered many many times before on this forum and is pretty well documented on Darrels web-site I thought you might have a go at it yourself. I don't think it's matter of being tight with code it's just that each and every application is a little different so it's not just a matter of here you go, use this it'll work exactly the way YOU want.
I have no way of testing this here so this may actually be more of a problem than help but since you seem reluctant to try yourself here goes nothing.
First you need to download the files from Darrels web-site and place them in the PBP directory (or in the project directory). ThenThen you need to configure the interrupt source and tell the system which subroutine to call when the interrupt occursCode:INCLUDE "DT_INTS-14.bas" INCLUDE "ReEnterPBP.bas"Here we tell the system that we want to trip an interrupt when TMR0 overflows. When that happens we want the UpdateCount subroutine to be called. That subroutine is to be written in PBP and we want the system to automatically clear the interrupt flag for us.Code:ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR0_INT, _UpdateCount, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM
Now you need to actually set up TMR0 so it interrupts at a suitable interval. At 20MHz it ticks a long a 5Mhz meaning , since it's 8bits wide, it'll overflow every (1/5000000)*256 = 51.2us. That'll be a little fast for you I think but luckily TMR0 has prescaler which you can use if disable the Watchdog timer. With the prescaler set to 1:256 you'll get an interrupt rate of (1/5000000)*256*256=13.11072ms or ~76Hz.
TMR0 is controlled thru OPTION_REG soThis should set TMR0 up in "free running mode" with a prescaler of 1:256 meaning it'll overflow every 6.5536ms.Code:OPTION_REG.5 = 0 OPTION_REG.4 = 0 OPTION_REG.3 = 0 OPTION_REG.2 = 1 OPTION_REG.1 = 1 OPTION_REG.0 = 1
Then you set up TMR1 as a counter as shown before.
Then you enable the interruptNow, every time the TMR0 overflow it'll call the Interrupt Service Routine called UpdateCountCode:@ INT_ENABLE TMR0_INTNow, PulseCount will be updated with the current speed automatically, in the background, once per second.Code:UpdateCount: Tick VAR BYTE PulseCount VAR WORD oldCount VAR WORD Tick = Tick + 1 If Tick = 76 THEN ' Count 76 interrupts to get roughly one second oldCount = PulseCount ' Previous count PulseCount.HighByte = TMR1H PulseCount.LowByte = TMR1L PulseCount = PulseCount - OldCount 'Take difference between this and the previous difference. Tick = 0 ENDIF @ INT_RETURN ;Return from ISR
Don't expect this to just work. I have no way of testing it here so use it as a starting point.
Read the datasheet and compare the settings, does it match, does it add up? Read Darrels website. Do you understand how it works.
I wouldn't expect to buy Flowcode and NOT having to read any documentaion. There ARE numerous example (here on the forum), there ARE a lot of people here to help, Darrel (who now works for MELABS) is here and if that's not enough you can always visit the forum at MELABS website where the other guys from MELABS answers questions too. I wouldn't expect anyone to write the application for you though.
/Henrik.




Bookmarks