How does DelayMS work?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

How does DelayMS work?

Post by blackcattech » Tue Jul 23, 2013 9:57 am

Does the DelayMS routine just do a series of nops, or does it use one of the timers?

The reason I ask is that I made a small change to a piece of software I'm working on and it stopped working, only getting so far. I found that the problem was that it was getting to a DelayMS(250) command and just hanging. The ISR was still running but the delay never completed.

The change I'm working on involves using Timer 0 so I was wondering if this is somehow affecting the Delay routine? If not, are there any known bugs in the routine that would cause it to just hang?

The odd thing is that the delay was working fine, I moved some of the setup code prior to it into a separate Sub and it just stopped. Most odd...

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Tue Jul 23, 2013 10:10 am

delayms does not use any timers but does use system registers - no idea what your ISR is doing but sounds like it might be touching a register used by the delay routine.

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Tue Jul 23, 2013 10:16 am

OK, that would make sense. Is there any way to identify what registers are used and what might be the cause of the conflict so I can do a work-around?

The software has been working fine for ages, I'm on V2 of the PCB, the only main change is the addition of a buzzer. This needs a square wave to drive it so I've added an ISR for Timer 0 which uses Toggle() to generate the square wave. Could this be the issue?

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Tue Jul 23, 2013 10:18 am

I should mention by the way that I do Save(0,FSR0,FSR1) at the start of my ISR, should that save the system registers or are they not ones saved by default?

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Tue Jul 23, 2013 10:44 am

> Save(0,FSR0,FSR1)

Yes, that should save the system registers OK. I'm not aware of any other problems which would cause delayms() to fail.

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Tue Jul 23, 2013 12:37 pm

OK. I have a timer in my ISR used to multiplex a display so I guess I can use that to replace the Delay function.

Post Reply