As some of you I’m currently busy getting the speed of my program up. I’m using a internal timer to measure the speed improvement. It’s the same timer as kurte mentioned before.
'==================================================================================================
;Variable declaration
lTimerWOverflowCnt var long ; used in WTimer overflow... Will keep a 16 bit overflow so we have a 32 bit timer
lCurrentTime var long
lTimerStart var long
lTimerEnd var long
Time var byte
;=============================- Interrupt definitions =======================================
;Interrupt init
ONASMINTERRUPT TIMERWINT, Handle_TIMERW
;============================== Start of CODE ================================================
; Initiialize Timer
WTIMERTICSPERMS con 2 ; we have 16 clocks per ms and we are incrementing every 8 so divide again by 2
TCRW = 0x30 ;clears TCNT and sets the timer to inc clock cycle / 8
TMRW = 0x80 ;starts the timer counting
lTimerWOverflowCnt = 0;
enable TIMERWINT_OVF
;================================ Main Loop =================================================
main_loop
gosub GetCurrentTime], lTimerStart
' Do all your main loop stuff here...
pause 200 'mS
gosub GetCurrentTime], lTimerEnd
' you can calculate your difference in time here...
Time = (lTimerEnd-lTimerStart)/WTIMERTICSPERMS/1000
serout S_OUT, I38400, [dec lTimerStart, " ", dec lTimerEnd, " ", dec Time, 13]
goto main_loop
;-----------------------------------------------------------------------------------
; Handle TimerW interrupt
BEGINASMSUB
HANDLE_TIMERW
push.w r1 ; save away register we will use
bclr #7,@TSRW:8 ; clear the overflow bit in the Timer status word
mov.w @LTIMERWOVERFLOWCNT+1:16,r1 ; We will increment the word that is the highword for a clock timer
inc.w #1,r1
mov.w r1, @LTIMERWOVERFLOWCNT+1:16
pop.w r1 ; restore our registers
rte ; and return
return
;-------------------------------------------------------------------------------------
; Simple function to get the current time and verify that no overflow happened
GetCurrentTime
lCurrentTime = lTimerWoverflowCnt + TCNT ; calculate the timer
if lCurrentTime.highword <> lTimerWOverflowcnt.highword then
lCurrentTime = lTimerWoverflowCnt + TCNT ; calculate the timer
endif
return lCurrentTIme
If I load this program in my phoenix it returns the starttime, stoptime and difference. So far so good.
If I load the program in my test-setup (BB2 + ATOM 28 pro) with this code it doesn’t do a thing at all! The ATOM works again when I remove the interrupt.
ONASMINTERRUPT TIMERWINT, Handle_TIMERW
I’m rewriting some parts of my code on this setup without any problems. Everything seems to work until I enable the interrupt…
I haven’t got clue what’s going on. Is my ATOM defect…? Any ideas…?
Is that the complete code or by chance to you have something like HSERVO enabled? The Hservo command uses the TimerW. Are you using the same compiler on the same machine (compiler set for pro 28)?
Not sure what else. I will try to setup soon so I can test on a couple of different boards as well. Still in the process of moving in and trying to get my network to work…
Like Kurte said, we need to know if there are any differences from the above code to what you are loading to the two different boards. If the above code works on one module it should work(as long as there are no changes) on another module.
If the phoenix using the same module or a different one? What board is it using? If it’s using a different module then program the module that works with the above code and after testing to make sure it still works move it to the BB2 test board and see if it stops working there. if so I’d say something(I don’t know what it could be) on the BB2 board is causing it. if however you are using two different modules and one works on both boards and one doesn’t work on either then there has to be something wrong with the module(again I don’t have any idea what it could be).
The code I’ve posted is the whole code that I try to load in the ATOM. It’s should return 3 variables on the serial port.
Both setups use a bot board 2 with a ATOM 28 pro so they should be identical. If I load the program in the phoenix, it works. If I move the serial cable to the test setup and program the same code it doesn’t work. It let me program it but there isn’t any output on the serial port.
I’ve placed a sound command in the code to do some debugging. If I place it somewhere before the pause 200 command it will beep once. There isn’t any sound if I place it behind it. If I comment out the interrupt command it starts looping and beeping…
There is one strange thing I’ve noticed though. The red led (A) is most of the time on. Only when I program the ATOM or write to the output it blinks… No Idea what that is but I’ve never seen it on one of the other boards…
I’ll try to change the ATOM’s or even the BB to see if it’s some kind of hardware problem. I’ll keep you posted.
I replaced the ATOM 28 pro with another one, programmed it and it’s working! The red led is also off again. I placed the defect chip in the BB to check if it was a bad contact but it had the same affect over again. Conclusion: defect ATOM
Is by chance the non-working one an older chip? I believe that early on the chips were with the 3664 and now is a 3694 which for the most part is very compatible, but there are some differences. I don’t see any obvious ones with the WTimer, but if it looks like you have an older one, I will try to look more closely!
The defect one has got a 3694. Led A also turns off if I use the other chip so i doubt if the interrupt is the only problem with this chip.
But I’m glad that I’ve found it! Now I can focus on the software again