PDA

View Full Version : Elapsed Timer Demo in a PIC12F675



Leonardo
- 15th November 2008, 18:10
Hello,

How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off. żIt is possible to do this?

Charles Linquis
- 15th November 2008, 18:37
If you just want 5 days then -

LED = ON

For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
PAUSE 60000 ; one minute
Next X

LED = OFF

Leonardo
- 16th November 2008, 14:40
If you just want 5 days then -

LED = ON

For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
PAUSE 60000 ; one minute
Next X

LED = OFF

Hey Charles,

Thanks for your answer but my concern is whether you can do with the Elapsed Timer because it seems to me a good idea.

Thanks

Acetronics2
- 16th November 2008, 17:13
Hi, Leonardo

looks Still some way to reach Leonard's code ...

ALL you have to do is check each second ( or min, if not so precise required !!!) Days-hours-mins-secs ( which are already existing variables ) and match your own values.

But forget the // LCD screen ...

Alain

Leonardo
- 16th November 2008, 22:35
Hi, Leonardo

looks Still some way to reach Leonard's code ...

ALL you have to do is check each second ( or min, if not so precise required !!!) Days-hours-mins-secs ( which are already existing variables ) and match your own values.

But forget the // LCD screen ...

Alain

Hello Acetronics,

You can give me an idea or an example to start.

Thank you

Leonardo
- 16th November 2008, 23:11
If you just want 5 days then -

LED = ON

For X = 1 to 7200 (60 minutes/hour X 24 hours/day X 5 days)
PAUSE 60000 ; one minute
Next X

LED = OFF

Hello,
This is the code I've tested with 1 minute and works well, then put 7200 can achieve the 5 days with a good presicion?.


led1 var portb.0
x var word

HIGH LED1

Top:

For X = 1 to 1 '(60 minutes/hour X 24 hours/day X 5 days)
PAUSE 60000 ; one minute
Next X

LOW LED1

goto Top


Thank you

Charles Linquis
- 16th November 2008, 23:57
The accuracy will be good if you are not using the internal oscillator. You need a crystal or external "can" oscillator for better than 2-3%. If you need really good accuracy, you can (temporarily) shorten the time interval to one day (or so) and compare it to a clock. For example: if you are 1.3% "fast" then increase the value after the PAUSE by 1.3% (60780). That should get you close enough.

Darrel Taylor
- 17th November 2008, 01:41
Yup, that'll work.
As long as it's the only thing the chip will be doing.

But to answer the original question...
> How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off
CLEAR
LED VAR GPIO.0
CMCON = 7
ANSEL = 0

Include "Elapsed.bas"

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

HIGH LED ; Start with LED on

Loop:
if DaysChanged then
DaysChanged = 0
if Days = 5 then LOW LED ; Turn off LED
endif
Goto Loop


Or you can add a blinky LED to show that it's still counting...
CLEAR
LED VAR GPIO.0
StatLED VAR GPIO.1
CMCON = 7
ANSEL = 0

Include "Elapsed.bas"

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

HIGH LED ; Start with LED on

Loop:
if DaysChanged then
DaysChanged = 0
if Days = 5 then LOW LED ; Turn off LED
endif

IF SecondsChanged then
SecondsChanged = 0
Toggle StatLED
endif

; Rest of the program goes here
Goto Loop


And you can still do other stuff at the same time. :)

Leonardo
- 17th November 2008, 16:55
Yup, that'll work.
As long as it's the only thing the chip will be doing.

But to answer the original question...
> How to use the Elapsed Timer Demo in a PIC12F675 to maintain a on led by 5 days and then goes off
CLEAR
LED VAR GPIO.0
CMCON = 7
ANSEL = 0

Include "Elapsed.bas"

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

HIGH LED ; Start with LED on

Loop:
if DaysChanged then
DaysChanged = 0
if Days = 5 then LOW LED ; Turn off LED
endif
Goto Loop


Or you can add a blinky LED to show that it's still counting...
CLEAR
LED VAR GPIO.0
StatLED VAR GPIO.1
CMCON = 7
ANSEL = 0

Include "Elapsed.bas"

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

HIGH LED ; Start with LED on

Loop:
if DaysChanged then
DaysChanged = 0
if Days = 5 then LOW LED ; Turn off LED
endif

IF SecondsChanged then
SecondsChanged = 0
Toggle StatLED
endif

; Rest of the program goes here
Goto Loop


And you can still do other stuff at the same time. :)

Hey Darrel,

In compiling I get this error because it will be.

<a href="http://imageshack.us"><img src="http://img231.imageshack.us/img231/9863/errorcv5.jpg" border="0" alt="Image Hosted by ImageShack.us"/></a><br/><a href="http://g.imageshack.us/img231/errorcv5.jpg/1/"><img src="http://img231.imageshack.us/img231/errorcv5.jpg/1/w626.png" border="0"></a>

mister_e
- 17th November 2008, 17:05
open ASM_INTS.bas file, there you'll discover ..


' --- IF any of these three lines cause an error ?? Simply Comment them out to fix the problem ----
wsave1 var byte $A0 SYSTEM ' location for W if in bank1
wsave2 var byte $120 SYSTEM ' location for W if in bank2
wsave3 var byte $1A0 SYSTEM ' location for W if in bank3

Leonardo
- 17th November 2008, 17:46
open ASM_INTS.bas file, there you'll discover ..


' --- IF any of these three lines cause an error ?? Simply Comment them out to fix the problem ----
wsave1 var byte $A0 SYSTEM ' location for W if in bank1
wsave2 var byte $120 SYSTEM ' location for W if in bank2
wsave3 var byte $1A0 SYSTEM ' location for W if in bank3

Steve,

Did not take into account the memory banks and compiles well, will do some tests and the results then I said.

Thank you

Leonardo
- 17th November 2008, 18:25
Steve,

I've done some testing with minutes and works extremely well using a 4-MHz crystal, the oscillator's internal PIC12F675 is not very accurate there is any way to use it with good presicion?.

Thank you

Darrel Taylor
- 18th November 2008, 00:36
Try adding ...
DEFINE OSCCAL_1K 1when using the internal OSC.

Leonardo
- 18th November 2008, 23:28
Steve,

Perform tests on a 4-MHz external crystal setting 1 hour and was led off in 56:41 minutes of taking a delay time of 3:06 minutes. Is it normal that delay?.

Thank you

mister_e
- 19th November 2008, 04:43
Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

I would guess you just use the internal OSC... probably where the huge gap come from.

Leonardo
- 19th November 2008, 18:15
Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

I would guess you just use the internal OSC... probably where the huge gap come from.

Steve,
I'm using an external 4MHz crystal and the code is this for PIC12F675.


CLEAR
LED VAR GPIO.0
CMCON = 7
ANSEL = 0

Include "Elapsed.bas"

Gosub ResetTime ' Reset Time to 0d-00:00:00.00
Gosub StartTimer ' Start the Elapsed Timer

HIGH LED ; Start with LED on

Loop:
if HoursChanged then
HoursChanged = 0
if Hours = 1 then LOW LED ; Turn off LED
endif
Goto Loop

http://img143.imageshack.us/img143/7228/programmerdh0.png (http://imageshack.us)

Leonardo
- 21st November 2008, 00:01
Can't tell, i never used it before. Would be of great help if you could post the whole schematic, code and configuration fuses.

I would guess you just use the internal OSC... probably where the huge gap come from.

Hello,

I doubt arises as to obtain such a delay of 1:20 hours and minutes.

Thanks