using settimer command twice stops timer counting

Dr_John

Member
- Apologies if this has been raised before -

I had a problem that sometimes the timer variable was not counting.
It would only count reliably if you turned the robot on twice, ON - OFF-ON , or used the hardware reset pin.
It would not count, if you left it off for 15 seconds (Capacitors discharged?)

The problem seems to be caused by a bug that meant that my settimer command was executed twice at the start of a robot race.

The settimer command was

settimer count 65535

I was using "timer" to count wheel rotations, and know when to stop at the end of the race. The bug meant that it never stopped.

It does work reliably if you put a "settimer off" command before the settimer command - you can then call it twice with impunity.

Pic Chip: 28x2
----------------

- Before I produce a full report, has anyone ever met this problem?
Dr_John
 

westaust55

Moderator
Nothing obvious come to mind.
That it apparently works when you cycle the power indicates that your pulses are connected to pin C.0.

Can you post your entire code so that folks here can review and see if there is something obvious causing the situation.
 

Technical

Technical Support
Staff member
As far as the PICAXE firmware is concerned it makes no difference if it is it a power on (after 15 seconds powered off) or a reset pin style of reset.

The fact that a reset pin reset always works could well imply the chip is not actually powered off when you think it was and hence not properly reset - maybe parasitically powered via an input/output pin connection?
 

stan74

Senior Member
Can we see the code? What value is the decoupling cap between pins 19 and 20? The only reset problem I think I've had is not programming. Sometimes I have to click asm then power the picaxe. Don't know if that's related though.
 

Goeytex

Senior Member
More likely a bug in your code or a design flaw in the electronics than a bug in the Picaxe firmware.

Let's have a look at your code and a schematic.
 

Goeytex

Senior Member
In the context, there can only be two possible sources of a "bug"... User code and firmware. If the OP did not specifically "say" it was firmware then what do you suppose was meant by "bug", his own code ? If he meant it was his own code, then why ask if others had run into the same problem? And why not post the code for review,

To me a firmware bug was clearly implied if not specifically stated.

The bottom line here is we need to look at the code and the connections/schematic to properly troubleshoot the problem and then determine the root cause and provide a solution.
 

Dr_John

Member
Thanks for all your posts . . .

I *will* post the minimal code that shows the problem.
I am in the process of reducing to the bare minimum.

I will attempt to reproduce it on a standard 28X2 module to cut out unknowns,
with c.1 output driving the c.0 counter input.

I suspect that using

settimer count 65535
settimer count 65535

in my program means that timer doesn't count properly, in some reset circumstances.

whereas a single

settimer count 65535

or a multiple:

settimer off
settimer count 65535
settimer off
settimer count 65535

works fine in all reset circumstances.

============================
I will post a circuit description and a minimal program,
but I think a note in the manual against settimer might be in order, saying that

settimer off

should be used , before issuing a second command.
- more later
 

Technical

Technical Support
Staff member
Th

I suspect that using

settimer count 65535
settimer count 65535
Indeed, this is almost certainly to the silicon issue explained in the 2014 post we linked above - see the Microchip errata also linked in that post. Using 'off' will switch the silicon interrupt off before you try to re-update the settings, hence working around the silicon limitation by totally ignoring any 'spurious event' (as Microchip calls it).

http://ww1.microchip.com/downloads/en/DeviceDoc/80000498G.pdf
 

bgrabowski

Senior Member
Try the workaround I use in my micromouse set up as a drag racer:

Settimer count 65535
timer = 0

I don't seem to get counting issues as long as I zero the timer variable after setting the timer count.
 

Dr_John

Member
This doesn't help Bernard (You might recognise me as Mr Tauros)
It is the duplicated settimer commands that stops the timer (sometimes).
If you switch on-off-on every time you run it it is OK.
If you leave it off for a few seconds then the duplicated settimer is a problem.

My solution is to make sure only one settimer is issued.

=====================================================
my test code:
Code:
; Test program to show strange result of repeat settimer count commands
; Dr John  17/3/17
; the test hardware is a 28x2 module running off a 9v PP3 battery
; c.1 is connected to c.0

#picaxe 28X2 'code for Picaxe 28X2

; outputs at 9600 baud.
sertxd (13,10,"Test settimer 17-3-17.bas",13,10) 

let dirsC = %00000010 ;c.1=output, c.0=input.

settimer count 65535               
;settimer off   		; including this line fixes the problem
settimer count 65535    ; removing this line fixes the problem

do

; repeat 7 times...
  for W10 = 0 to 6
    timer = 0

; output 10 pulses    
    for b0 = 1 to 10
      high c.1  : pause 25
      low  c.1  : pause 25
    next b0

; display timer 
    w1 = timer  :  sertxd (#w1,",") 
  next W10

; another settimer to see what happens             
  sertxd (13,10,"settimer count 65535 ",13,10) 
  settimer count 65535  
loop
===============================================
printout if starting from cold:


Test settimer 17-3-17.bas
0,0,0,0,0,0,0,
settimer count 65535
18,20,20,20,20,20,20,
settimer count 65535
18,20,20,20,20,20,20,
settimer count 65535
18,
======================================
printout if you switch off then on during the initial 0,0,0s
======================================

Test settimer 17-3-17.bas
0,0,0,
Test settimer 17-3-17.bas
18,20,20,20,20,20,20,
settimer count 65535
18,20,20,20,20,20,20,
settimer count 65535
18,20,
==================================
It does seem to be a silicon issue
I have got used to the double counting ! but why only 18 on the first round?
 
Last edited by a moderator:

Technical

Technical Support
Staff member
18 may be because you don't have any falling edge before the next rising edge after re-issuing the 'setint count'.

Please try this:

1) replace 'let dirsC = %00000010' with 'high c.1'
2) swap high and low in the inner loop around.

What results do you then see, as by doing this you will always have a falling edge after any new setint command

CaptureFallingEdge.PNG
In simpler terms, after 'setint count' is issued, it won't start counting rising edges until it has actually seen a falling edge occur.
 

Dr_John

Member
Yes - Thanks:
===================

Test settimer 18-3-17.bas
0,0,0,0,0,0,0,
settimer count 65535
20,20,20,20,20,20,20,
settimer count 65535
20,20,20,20,
===================

Many thanks to one and all for clearing this up.
 
Top