1 sec interrupt routine @ 32Mhz issue on X2

BUSHBANDIT

New Member
We are a non profit enginnering department in a teaching hospitail and have used the PIXAXE (and pic/ AVR) chips for rapid development of customised H/W applications to assit in patient care and providing modification aids and adaptions for the disabled -ie wheel chair controller to interface to communication aids or PC for example.

we have an application that has been running well on the 40 X1 @16mhz.
recentely we have shifted to the 40x2 and caried out the required syntax changes to the existing code. we wiish to eventually expand the functionality of the exixting unit and the responsiveness.

However since the mirigration the interrupts have been giving us grief, we are trying to achieve an accurated 1 sec timer, 10minute timer (as all pins are used including 4 i2c devices ) without the use of a RTC.

ISSUE !
i coded have set that appears not to work

setfreq em32
settimer t1s_16
(as tls_32 word bite dosent exist, and the required count exceeds the word restriction)

The interrupt subroutine that stands at the moment is below.
interrupt:
inc w27 (this being the 10 minute tracking routine as well)
if w27 >599 then
w27 = w27-600
endif

set_timmer:
toflag = 0
timmer = 65534
setintflags %100000000, %100000000

with in the main loop there is routines of
writing to a serial LCD
reading one wire temperature devices
reading 4X 12c linear technology LTC4151
reading digital i/o from switches
commputational routines with data logging to a UALFAT_TF
communicating serially to a smart LIFEPO4 battery
and a serial PC connfiguration port

these are all timed based driven events -

ISSUE 2
we also want a more interrrupt driven based code routine would the below codding be reasonable?

interrupt:
select case flags
case toflag
inc w27
if w27 >599 then
w27 = w27-600
endif
goto set_timmer
case hserflag
proscess serial and reset interrupt
case....and so forth
end select


Thanking you for your time and assistance
Greg
 

MartinM57

Moderator
ISSUE !
i coded have set that appears not to work

setfreq em32
settimer t1s_16
(as tls_32 word bite dosent exist, and the required count exceeds the word restriction)

The interrupt subroutine that stands at the moment is below.
interrupt:
inc w27 (this being the 10 minute tracking routine as well)
if w27 >599 then
w27 = w27-600
endif

set_timmer:
toflag = 0
timmer = 65534
setintflags %100000000, %100000000
Hi Greg - welcome

Don't really understand the above - please expand on "appears not to work"
- doesn't do anything at all
- works but not accurate
- get a syntax error at "timmer = 0" :p
- doesn't get to the first interrupt for ages as you haven't set timer to 65534 at the top of the code
- or something else?
 

Technical

Technical Support
Staff member
You can't do this:

Code:
setfreq em32
settimer t1s_16
We assume you are thinking this will give you a 0.5s delay - it won't. The settimer value needs to be configured to the actual frequency in use.

In the second case the idea works but your code doesn't. Try this instead

Code:
interrupt:
 
if toflag = 1 then 
  inc w27
  if w27 >599 then
    w27 = w27-600
  endif
  goto set_timmer
 
 
elseif hserflag = 1 then 
  proscess serial and reset interrupt
 
else
  ...
end if
 
return
 
Last edited:

BUSHBANDIT

New Member
how do you get at 32mhz a 1 sec interrupt timer

Thankyou for responding.

Sorry. i did make a mistake in the typing of the timer command in the initial description. i do ininitialise the timer in slot zero of the 40X2 to 65534 but left it out in the transfering to post

The interrupt code does work but i dont get the required interval and time. Varation from the routine is widely erratic.(tried toggling an i/o pin and injecting into a scope and precision electronic hp timer)

I am trying to achieve a 1 sec interrupt while running on the 32Mhz internal clock.

If my approach is floored what is the best way to get an accurate 10 minute time (and extract a 1 sec and 5 sec marker to do timed i/o routines)

There dosen't exist a t1s_32 in conjunction with the settimmer command and if you use the formaula according to the manual to calculate what to set the count to it exceeds the 65535 of the word.

Many thanks for any help or advice given.

Regards
Greg
 
Last edited:

hippy

Ex-Staff (retired)
One technique is to interrupt every half second, then only handle a 'seconds tick' every two interrupts ...

Code:
#Picaxe 40X2
#Terminal 38400
#No_Table
#No_Data

Symbol tick     = b0
Symbol secs     = b1
Symbol fiveSecs = b2
Symbol mins     = b3

Symbol MHZ                   = 32

Symbol MINOR_TICKS_DIV       = 256 / MHz
Symbol MINOR_TICKS           = 500000 / MINOR_TICKS_DIV

Symbol HALF_SECOND_INTERRUPT = 65536 - MINOR_TICKS

Pause 2000

SetFreq EM32

SerTxd( "Start", CR, LF )

SetIntFlags %10000000, %10000000
timer = $FFFF
SetTimer HALF_SECOND_INTERRUPT

Do : Loop

Interrupt:
  tick = tick ^ 1
  If tick = 0 Then
    secs = secs + 1
    SerTxd( #secs, " " )
    fiveSecs = fiveSecs + 1
    If fiveSecs >= 5 Then
      fiveSecs = 0
      SerTxd( "< 5 secs > " )
    End If
    If secs >= 60 Then
      secs = 0
      mins = mins + 1
      If mins >= 10 Then
        mins = 0
        SerTxd( "< 10 Mins >", CR, LF )
      End If
    End If
  End If
  timer = $FFFF
  toflag = 0
  SetIntFlags %10000000, %10000000
  Return
 
Last edited:
Top