Set a pin high for a second every day...?

ChedderCheeser

Senior Member
Hi guys. I am planning to make a little project that will activate a counter module every day. How can I set up my 08M to pulse the pin every DAY? ex.

Code:
main:
    pause ONE-DAY
    high PIN
    pause 1000
    low PIN
goto main
THX!
 

Svejk

Senior Member
Do you have a paticular time of day in mind? If not, you can use the night to day transition to set your pin interfacing with a simple LDR.
 

manuka

Senior Member
CC: A simple approach could just use cascaded WAITs for 86400 seconds (being 60 seconds x 60 minutes x 24 hours). BUT all the usual request background info. is REALLY first needed. Hence -how accurate does it have to be? Will the temperature be constant? Approx.what time of the day/night does it switch? Indoor/outdoor (& if the latter can the sun be "seen")? Will accumulated errors be an issue? What budget? Battery powered ?

Requests for technical help often NEED excrutiatingly FULL details, otherwise it's perhaps like turning up to a supermarket & bluntly saying "I want food"...
 
Last edited:

tracecom

Senior Member
I think this will do what you want, but there are at least three problems: first, it has some inherent inaccuracy because of the PICAXE clock inaccuracy; second, the PICAXE is not available to do anything else; and third, the PICAXE won't respond to programming while it's paused. Better to use a RTC.

Code:
main
	high 2
	pause 1000
	low 2
	for b1 = 1 to 24	'Sets number of hours to pause.
		for b0 = 1 to 60	'Sets number of minutes to pause.
			pause 60000	'Pauses for 60 seconds.
		next b0
	next b1
goto main
 

MartinM57

Moderator
If that is the case, then Microchip App Note AN521 :interfacing to AC PowerLines" would be worth reading:
http://ww1.microchip.com/downloads/en/AppNotes/00521c.pdf
...if only to note that the PIC(AXE) circuit is one resistor away from live mains.

@ChedderCheeser - please don't do it this way. Period.
@ChedderCheeser - please respond to post #3 or else the collective will come up with even more solutions to no real requirements ;)
 

srnet

Senior Member
@ChedderCheeser - please don't do it this way. Period
Indeed.

That type of 'solution' is for the experienced, and requires additional safety precautions.

Not difficult mind to use a transformer from a disgcarded linear power supply (as in wall wart) and get the AC from the low voltage side of the transformer, that would be a LOT safer.
 

hippy

Ex-Staff (retired)
I had to face this challenge when wanting to use a PICAXE to 'push a button' on a digital picture frame once a day at a fixed time.

Accumulated drift is a problem without a crystal, no RTC and no mains cycles to count, but shorter periods to triggering were tolerable in my case. I ended up using a plug-in mains timer so the picture frame is turned off over night ( an environmental benefit in itself ), when it turns on the PICAXE program is then quite simple - delay, trigger button push, sleep forever.
 

westaust55

Moderator
Indeed.

That type of 'solution' is for the experienced, and requires additional safety precautions.

Not difficult mind to use a transformer from a disgcarded linear power supply (as in wall wart) and get the AC from the low voltage side of the transformer, that would be a LOT safer.
I concur.
Would also suggest that the initial post by MPep stated "derived from" as opposed to "directly connected to" thus the suggestion should b seen as a guideline as the transformer into. Say 7805 regulator would still be at too high a voltage for direct connection of ELV levels to the PICAXE chip.

Then in this world of litigation such warnings as above become a necessity.
 
Last edited:

Paix

Senior Member
The Borg collective has detected the frenetic creativity that is CheddarCheese's thought process and are drawing up plans to harness this powerhouse of energy by a process of assimilation. Stand by for an 08M2 implant to connect you to the greater interstellar network Chedder'.

I suspect that testing and calibrating process for your DAY delay might not be fast enough for your agile mind. :) If you could bottle enthusiasm and imagination as a cocktail and flog it, you could become an entrepreneurial millionaire . . .

Not only that, your name could become a household name in the food and drinks business (couldn't help myself).:)

Have a good summer.
 

ChedderCheeser

Senior Member
Post #3 - Well, It is going to be indoors. Probably out of reach by the sun. Powered by an ac-dc converter. A good one. Temperature will be constant ish.. it may vary a bit... by like 5 degrees at the most. I dont need it to be at any specific time of day. Preferably at like 4:00 AM. I think that that would actually work fine for what I am doing... Maybe I should just.. power up the circuit at 4:00 AM so that that would be the time it does the next pulse? Also, thanks for the code! I think I will use it. I'll let you guys know how it goes.
 

Jamster

Senior Member
If you have acsess to an RTC (DS1307) then you can use this code:
Code:
 symbol seconds=b0
 symbol mins=b1
 symbol hour=b2
 symbol temp=b3
 symbol day=b4
 symbol date=b5
 symbol month=b6
 symbol year=b7
 
 ;set these to the trigger hour
 symbol trighour=4
 symbol trigminute=00
 
 i2cslave %010000,i2cslow,i2cbyte
 
 ;REMed out line below is to set current time
 ;   min|hour
 'writei2c 1,($16,$20)
 
 do
 pause 1000
 readi2c 1,(mins,hour)
 
 ;Convert values to something usable
 temp = mins AND %00001111
 mins = mins AND %11110000 * 10 / 16 + temp
 
 temp = hour AND %00001111
 hour = hour AND %11110000 * 10 / 16 + temp
 if mins=trigminute and hour=trighour then
  ;TRIGGER EVENT HERE
 endif
 loop
 

erco

Senior Member
Use a cheap wristwatch with a daily alarm signal: cheaper, easier, & far more accurate.
 

ChedderCheeser

Senior Member
I think this will do what you want, but there are at least three problems: first, it has some inherent inaccuracy because of the PICAXE clock inaccuracy; second, the PICAXE is not available to do anything else; and third, the PICAXE won't respond to programming while it's paused. Better to use a RTC.

Code:
main
	high 2
	pause 1000
	low 2
	for b1 = 1 to 24	'Sets number of hours to pause.
		for b0 = 1 to 60	'Sets number of minutes to pause.
			pause 60000	'Pauses for 60 seconds.
		next b0
	next b1
goto main
How accurate is it?

If you have acsess to an RTC (DS1307) then you can use this code:
Code:
 symbol seconds=b0
 symbol mins=b1
 symbol hour=b2
 symbol temp=b3
 symbol day=b4
 symbol date=b5
 symbol month=b6
 symbol year=b7
 
 ;set these to the trigger hour
 symbol trighour=4
 symbol trigminute=00
 
 i2cslave %010000,i2cslow,i2cbyte
 
 ;REMed out line below is to set current time
 ;   min|hour
 'writei2c 1,($16,$20)
 
 do
 pause 1000
 readi2c 1,(mins,hour)
 
 ;Convert values to something usable
 temp = mins AND %00001111
 mins = mins AND %11110000 * 10 / 16 + temp
 
 temp = hour AND %00001111
 hour = hour AND %11110000 * 10 / 16 + temp
 if mins=trigminute and hour=trighour then
  ;TRIGGER EVENT HERE
 endif
 loop
Very nice. I sadly dont have it though. I could get it...

Use a cheap wristwatch with a daily alarm signal: cheaper, easier, & far more accurate.
Good plan... but.. I dont REALLY need a picaxe for that do I? Unless I wanted to trigger like.. a servo or something?
 

srnet

Senior Member
Not sure I understand the difficulty here.

At the time of day you want the pulse to be sent, press a button connected to the PICAXE where a simple program scanning for the switch sends the pulse/
 

tracecom

Senior Member
How accurate is it?
It varies from one PICAXE chip to the next. I had one 08M that was very close: it took 21604 seconds to complete a pause routine that was supposed to be 21600 seconds. But even that 4 second difference in six hours translated to 16 seconds per day, or 97 minutes per year.
 

Jamster

Senior Member
Yes the code will definatly work with that, I have the DIP version so can help with any debuging if needbe.

P.S. Lazy...:D
 

MartinM57

Moderator
Post #3 - Well, It is going to be indoors. Probably out of reach by the sun. Powered by an ac-dc converter. A good one. Temperature will be constant ish.. it may vary a bit... by like 5 degrees at the most. I dont need it to be at any specific time of day. Preferably at like 4:00 AM. I think that that would actually work fine for what I am doing... Maybe I should just.. power up the circuit at 4:00 AM so that that would be the time it does the next pulse? Also, thanks for the code! I think I will use it. I'll let you guys know how it goes.
The most important request in post #3 is accuracy - which also needs to be extended to drift


e.g. +/- 2 seconds per day, zero average drift
e.g. +/- 2 minutes per day, +/- 30 minutes a month drift
etc

So what are we talking about for this "counter" - just an elapsed days counter, right?
 

hippy

Ex-Staff (retired)
There's merit in using a wristwatch, though I'd go for a digital alarm clock. First it's easy to set and adjust, it's usable as a real world clock, and if using an in-built piezo for triggering you'll probably want to use a PICAXE to turn that one minute or longer signal into something you can use for what you are controlling so there's still a PICAXE project element to it. If you're lucky you might find a radio controlled alarm clock cheap - last one I found in a garage sale was 25c.

So really it's a toss-up between a DS1307 and the bits that needs or a wristwatch / alarm clock.
 

srnet

Senior Member
I would go for the mains timer approach, as mentioned earlier.

Simple, cheap (£4ish delivered off eBay), accurate, useful for lots of other things too.
 

meridian

Member
Use a cheap wristwatch with a daily alarm signal: cheaper, easier, & far more accurate.
I did that years ago! Used a watch with alarm, sat in on a mic which went to a counter chip, can't remember now. After 10 beeps, relay went on, power to radio or something.

paulr
 
Top