BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:12 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Mad Hatter
PostPosted: Thu May 19, 2011 1:50 pm 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
Thanks Kurt!

I see a multiplier and a divider, what rate does this timer then count at? 1mS (1KHz)?

Although I think you're providing a "get time" function. That means one has to "poll" to wait for a specific time.

I want to set up a timer to generate an interrupt at a 1Khz rate. Can we write an interrupt handler in Basic Atom? This interrupt handler would then do the following:

Code:
SystemTick2 = SystemTick2 + 1   ; 1mS timer for delays

Tickcount = Tickcount -1

if (Tickcount = 0)   then
    Tick = TRUE;                  ; Tick rate 100mS
    Tickcount = 100;
endif


I suppose it could all be in assembly, as long as the two variables, Tick and SystemTick2 were accessible from Basic.

in use, I clear SystemTick2, then check periodically for it to reach a prescribed value. Similarly, the Tick flag is checked in a main loop, and if it is set, a subroutine is called, and then the flag is reset. This way, there is no "Blocking" for functions.

Tick allows me to service stuff like sensors at a periodic rate of 10/sec, and SystemTick2 allows me (typically in a state machine) to "check back" and then proceed to the next state when SystemTick2 reaches a preset value. Basically simple "real time" stuff.

thanks,

Alan

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: Mad Hatter
PostPosted: Thu May 19, 2011 2:53 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
I am using TimerB1 with a divider of 8192. So each clock tick is 8192/20000000 or .4096ms. Could use a different clock divider but I went this way for phoenix as we did not need that high of a resolution and with this we only have about 9.5 interrupts per second... I have both multiplier and divisor to get to ms as that what was needed to convert to ms without real values...

So you would like to interrupt every 1ms or every 20000 clocks. With a BAP I don't think you can get this 100% accurate, but with with the H8/3687 you can get somewhat close...

That is, with TimerB1 you would probably use the divisor of 128 as 20000/256= 78.125. You can not use the divisor of 64 as this would exceed 256. It appears like The 3687 added a preload register, which allows you to set it to count up from a location so it does not have to start at zero.

So you could then maybe set:
TMB1 = 3 ; divide by 256
TLB1 = 256-78

From this you can setup the timer interrupt. Does not need to be asm, could be simply
oninterrupt TIMERB1INT, HANDLE...

Hope that makes sense.
Kurt


Top
 Profile  
 
 Post subject: Re: Mad Hatter
PostPosted: Thu May 19, 2011 3:20 pm 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
That makes sense. It doesn't have to be 100.00% accurate. Even mS resolution isn't really necessary.

I'll want it in my next Mad Hatter code.

It would be nice if we had a provision for LIB functions on Basic Micro. Something like the MsTimer2 stuff of the Arduino. The MsTimer stuff is useful enough, I'd like to see it put into BM.

Thanks!

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO