Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Timer comparison on a PIC in assembly

Status
Not open for further replies.

marting

New Member
Hi,

I am strugling with a problem on a PIC. I have an app written in ASM that is used as a timer module. It has a build in klok, and a user config. timer.
The problem I face is that I cannot get the ASM routine to check if the current time is between the on/off time of the timer (so it will turn on a output).

I made one solution with a litteral register (in which the values of the time and timer are stored) comparison, and that works fine, until you change the timer setting. In that case it will only get active the next time (so this could be a day) the litteral comparisson succeeds.

What acctually is going wrong is that fact that a timer setting can be set over midnight. Ie.

T-On = 17:00
T-Off = 23:00
this works without any problem..but this is what I stuck on:

T-On = 17:00
T-Off = 02:00

(remember when comparing the time, you are only using 00-23 ..)
I would prefer a hint in ASM, but a flowchart might work as well..

Thanks
 
Why not check if the on time is after the off time and reverse your comparison. That is, check if it is between the off times.

So, with your examples.

T-On = 17:00
T-Off = 23:00

You say this works fine and so I assume you can check if the current time is greater than T-On and less than T-Off. If it is then your timer is ON.

T-On = 17:00
T-Off = 02:00

With this example, because T-On if greater than T-Off, check if the current time is greater then T-Off and less than T-On. If it is then your timer is OFF.

HTH

Mike.
 
Hi mike,

Think its just the push I needed.. Ive made simple if..then statement.
I bvelieve this should do the trick?

l = 1

If ton > toff Then
If h > toff And h < ton Then
l = 0
End If
Else
If h < ton Or h > toff Then
l = 0
End If
End If
 
I think your nearly there.

in basic it would be

Code:
If Ton > Toff then
	l = 1
	if h > Toff and h < Ton then
		l=0
	endif
else
	l = 0
	if h > Ton and h < Toff then
		l=1
	endif
endif


Mike.
Edit just trying something.
㏀㎌
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top