How to test flags (timer overflow) without interrupt [08M2]

Bendbau

New Member
Hi,

I'm new here, as active member. I have read through this forum a lot and most of the time, found answers to my questions. But this time, I can't find the answer I'm looking for.

I am making a little time base to feed a clock signal in logic circuits.
The set up is quite simple, a picaxe 08M2, a potentiometer to vary the frequency/choose the options in the menu, a momentary switch to navigate the menu (change frequency range, pulse with, ...) and a AXE133 module to display to informations.

The loop for low frequency values is short: reading the value of the potentiometer, sending the value to the display, and, at least in the plans, testing the timer flag.
I already have an interrupt running on the push button, that's why I want to be able to test the timer flag in the loop when I am running at output frequencies lower than 200 Hz (planing on using pwm function in another loop for anything higher than 200)

But when I write this, I get an error message:
Code:
if toflag = 1 then
      toggle C.1, C.2             'toggle output and inveted output
      gosub timing                 'go to timer reset subroutine
endif
The IDE tells me that "toflag" is an unknown symbol.
I previously tried to test the "timer" variable for my timing function but I have the same problem, the IDE tells me that "timer" is an unknown symbol.

Is there a way to access the variable "timer" or the timer overflow flag without an interrupt?
If not, I can still use a latch on my push button and use an interrupt for the timing function but I would like to avoid it.



Thanks if someone is able to help me here

Ben
 

AllyCat

Senior Member
Hi Ben,

Welcome to the forum. The M2 chips do not have a "timer" function (only X2 chips do), but a "time" variable, which normally increments once per second. The only "interrupts" which M2 chips support are "polled" and then only (some) input pins can be tested. More details are in the appropriate command reference, online or in Manual 2.

The (interpreted) PICaxe Basic is rather weak (slow) for doing on-the-fly timing functions, but what you require may be possible using the (base PIC) "Timer 1". The PICaxe operating system sets this to (normally) run at 1 MHz and overflow every 20 ms (the 16-bit counting sequence is 45536 to 65535), but you may struggle to over-ride this (for any useful length of time). There is currently a rather similar thread on the forum so I won't go into more detail here.

Most of the Microchip base chip SFRs can be accessed via PEEK/POKESFR commands, so ask if you need any help interpreting or applying them. You will need to write your own SYMBOL commands for the SFRs and/or their flags since they are not part of the PICaxe operating system.

Cheers, Alan.
 
Last edited:

Bendbau

New Member
Hi Alan,

Thanks a lot. It is not really the answer I was hoping for, even though that's what I was expecting.
I gave it a go:

Code:
' 016h TMR1L
' 017h TMR1H

#picaxe 08M2

init:

setfreq m32
symbol TMR1L = b0
let TMR1L = %00010110                              '$016h => bank0 (%000.....), address 16h (%...10110) 
symbol TMR1H = b1
let TMR1H = %00010111                             '$017h => bank0 (%000.....), address 17h (%...10111)
let dirs = %00000101
high C.2
wait 1
low C.2                                                    'let me know it's ready
pause 50

main:

do
	peeksfr TMR1L, b2                                         'retrieve value
	peeksfr TMR1H, b3
	serout C.0, N4800_32, (#w1, 13, 10)                'debug (IDE crashes at baudrate > 4800, plus LCD display doesn't seem to handle more either)
	toggle C.2	                                                  'Connected to logic analyzer
loop

end
It looks like I got the address of the timer1 register wrong because it gives me the same value for every single reading (unless the timer overflow at exactly the same frequency as I read it,... doubt it°
But anyway, the best frequency I achieved is 63Hz at 32MHz clock (I'm limited to a 4800baud rate), with a bit of a chaotic duty cycle. And that's with a short loop so it looks like I'll have to give up on doing timing critical stuff with the PICAXE's and bite the bullet and get into PIC programming. Unless I got something really wrong in my code that can fix my problem.


Thanks anyway.

Ben
 

AllyCat

Senior Member
Hi Ben,

Your SFR addresses look correct, but you can simply write symbol TMR1L = $16 etc.. You can also write peeksfr TMR1L,b2,b3 but I don't think that makes much difference to the speed.

However, the serout may be having much more influence than you realise (but still a lot less than a DEBUG). In addition to the basic bit periods, the PICaxe tends to extend the intercharacter time (or increase the number of Stop Bits) to give the AXE133 time to process each individual byte. So the serout may be increasing the loop time by almost a factor of ten.

Also, the serout disables interrupts so I believe the processing of the Timer 1 overflow/reload can get delayed until the serout has completed. That can lead to the timer always reporting the same, or similar, values, even for apparently asynchronous program code.

One improvement might be to send (individual) serial bytes using hserout , which happens to use the same pin (c.0).

Cheers, Alan.
 
Top