Hi,
So I'm running the DS1302_Demo and I'm interested in modifying it a little bit. I connected an LED and would like the LED to light up at a certain time... Say, whenever it's nine o'clock (am or pm) I want the LED to light up. I currently have the LED connected to PIN 15, so I tried something like:
If hrs = 10 THEN (for 10 o'clock)
HIGH 15
ELSE
LOW 15
ENDIF
However it's not working. I think it's something to do with hrs not actually being stored as 10, since it's HEX2, but I'm not sure about that, or where would be the place to put this code into the DS1302_DEMO code.
The problem is the literal value and the perceived value are two different things. In BCD each digit is considered to be 0-9. However if you simply increment the value you will eventually get illegal values. You're checking for a 10 (Decimal), but as you mentioned, the data is displayed using HEX2 because it treats each digit separately. The only thing you can do is put a $ in front of your 10 ($10) and then it will detect when the hours are at ten o' clock. If you add the dollar sign to your value above your LED should come on at 10 and stay on for an hour. Remember, the HEX2 formatter just causes the 2 digits to be treated individually.· I hope this helps. Take care.
Chris (seeing you are the guru on this) Im having a problem with stability on a project Ive recently created. It is a relay controller. Im using a BS2 and an DS1302 for a RTC. The DS1302 will run for a number of hours then randomly the seconds will count up to some bogus number (e.g. 68, 3D, etc). I had tried the crystal soldered next to the DS1302 but have now soldered the crystal directly to pins 2 and 3. No matter the instability occurs. I have included a picture of the project. Any suggestions on what to do? I have the same configuration of BS2 and DS1302 breadboarded and its rock solid.
Several things come to mind looking at your system...first of all I cannot see the various relays and I wonder if they have clamping diodes across the coils. Along the same lines I wonder what event seems to cause the issue...is it a certain combination of relays? It could be that you're either browning out the supply or creating EMI/RFI noise that is affecting the clock circuit. Do you know if your program is restarting when this happens? Finally, if all electronic issues are rules out it could be that at some point the values are incremented in the wrong mode. For example, incrementing a BCD value by just adding one to it will cause illegal BCD values.
I would say I would need to see the code and schematics to help you isolate that kind of problem.
I'm new to Stamps. I saw your thread about the date, time and seconds and was wondering how you made that program. Is your code available to look at? Thank you for your time.
Art
Got my DS1302 and crystal in the mail, and had some time to play today ...
Demo works fine for me, and was able to put together a separate program to set time/date/day ect, then just incorporate the functions to get and display the time,ect in my main program. Was kinda wierd , tho - I hooked up 2 AA batteries to store the time, and noticed some wierd results in the display awile later, gibberish in the time display, or incorrect numbers. Of course, the last thing I tried was disconnecting the batteries and assumed the IC or crystal or connections were screwy . Disconnected the 2 AA's and everything works fine( think I just have a flaky connection between B.B. and bateries), except for the below...
Just one thing I am having trouble with - and was wondering if you could toss me a hint on how to display everything ( Day, MM/DD/YY, HH:MM [noparse][[/noparse]SS] , AM/PM ) on a single line in debug window using SEROUT ?
Trying to solve it myself, but aggggh I ...am...drowning.....in Cisco , electronics and Maths and my brain cant seem to grasp the solution
Edit: hah! I got it -
sorrry to mess up your thread, Chris . Took a bit of work to string it all together at the exact position I wanted in the debug, but it works wonderful now! The loop with the "day" and the AM/PM stuff threw me for a ..errr loop, but its all good.....
It now starts at 0,5 in the debug, prints DAY mm/dd/yy hh[noparse]:mm:[/noparse]ss AM/PM
Whoopee!
AHHHH the joy of discovery!
Aloha,
Robert
Post Edited (Robert@HCC) : 1/19/2006 9:16:01 AM GMT[/QUOTE]
Ok, so I downloaded the timekeeping template. After messing around with the pins for a little while, I got it to work. The only problem was, it only worked for a day. The next day, I got on to use it and the debug screen just said SUN 01/01/00 00:00:80. I downloaded the timekeeping demo, and that works fine, so it's not the chip. I think it may be the code.
I had the same problem before I connected a "good" battery to pin 8 on the DS1302. You might attach your code and a schematic. That way we have a chance to see what could be causing your time reset.
Actually, I figured out my problem. The template wasn't supposed to be able to work right from the start. I needed to set the time before the template would work. But thanks
I've just bought some DS1302 chips from Parallax in order to create a solar tracking system based on real time calculations.
For my project I have used the propeller proto board and I have build the following time circuit using the DS1302, a crystal 32.768 khz and a 3V lithium battery CR2032.
The code I have used is the"DS1302_full-demo.spin" and it is based on "DS1302_full-demo" Object.
Runing the code I can setup the DS1302 chip. I can give the Date and the Time successfully.
The DS1302 keep the given time even after a current outage.
However when I execute the above code, the result on the serial telminal screen, shows that the Clock stick at the same time (the time that I give in the setup).
Can you give me any idea why does it happens? What is going wrong?
P.s Thanks for this thread and the given codes! It gives the best explanation about the DS1302 and BasicStamp. I look forward to see from you a similar presentation (like this thread) for the function of DS1302 using the propeller!
I think that the problem I described above happens because I don't use the appropriate 32.768kHz crystal that suggest Parallax.
Instead of this crystal I use a "Hosonic 32.768 B221" Ctystal.
Unfortunately I hadn't realized the necessity of the crystal when I ordered the DS1302 chips and I can't found these crystals here in Patras. I think that I have to make a new order from parallax.
I have this demo working with an LCD. I am planning to incorporate it into the Home Monitoring system I'm working on to place a Time and Date stamp on a PINK and have a webpage record the last Date/Time a particular sensor state is changed.
Question: What's the best logic regarding placing this code and and having the remainder of the project's code access it when Date/Time data is required, but continue to run? I don't need to display the Date/Time continually. I only need to have it when it is requested. I noticed the "place your main routines here" note in the template but my main code uses 5 slots so I'm not sure if it would be practicle to place all of that code in this loop. All in reference to multiple slots on a BS2e.
My thought is to use this code as part of an "initialization" in Slot 0 that will run once in the beginning when the Stamp is powered up to set the Date/Time. The DS1302 will run in the background to maintain the Date/Time. The Main code would then "loop" from the last Slot to Slot 1 to keep the program running.
Then, when a sensor state is changed, I would have to to the following:
GOSUB to the Get_Time subroutine to read the DS1302
GOSUB to the Show_Time subroutine to update the STAMP variables
SEROUT the STAMP's Date/Time data to Pink variables.
Is that a reasonable approach? Or could I delete the Show_Time routine and go right to the SEROUT?
Thanks Chris,
Embarrassingly, I happen to have a DS1202 (not the DS1302) that I want to finally use and this code seems to be fine for it. I think it was in one of my first order from Parallax.
Looks great, and I want to use it in a project I'm working on, I downloaded the BS2 code and related content from Nuts and Volts; but before I run it for the 1st time, I got 2 questions;
#1) On the Schematic "C3- 0.1uf" connected to 5V and Ground, Under the MAX7219; I'm a bit confused, do I connect C3 to the MAX7219 5V or is it part of the Power Suppply?
#2) On the LM386, can I replace "C8- 0.05uf" with a diff CAP, like a "0.068uf" or something near +/-
C3 was intended to be a bypas cap placed close to the MAX7219. It's power pins will connect to the same supply pins as the cap, but being close to the MAX7219 will help filter noise in the supply created by the MAX7219. I should have notated the placement of that cap rather than just left it floating. Thanks for the feedback.
You can change the value of that cap to a .1uF and the resistor to a 10 ohm if you prefer. That circuit if basically a snubber circuit which prevents high frequency oscillation.
done with the final pieces. I used a 0.068uf Cap on C8, added an LED to indicate power, a diode on the in of the 7805 power supply for polarity/safety reasons, and it works GREAT.
Will add bottons, other sensors, ect, .... thanks again for the quick reply and nice project. :nerd: :thumb:
I seem to have problems with both the demo and template programs on here. when i use the Demo one it skips step 1 (i've included a capture of the debug screen) so i can't set the time! on the template one, it keeps putting zero after zero without stop (i've included another capture for that too). I'm only a novice programmer and this is waaay over my head but i need to use this chip for my project. any suggestions? I didn't edit the program at all and the pins used are 0-2 like they should be. if anyone has the time i could really use a guide for this project as almost all of it is over my head. will probably take a couple hours.
EDIT: for some reason i was able to re-download the program and it worked? i was able to set the time, no issues. but then when i pressed 2 to look up the time, it still said 0 for all. it didn't save what i did.
second edit: ok, i'm a complete idiot. i had the data i/o and the clock pin backwards. after swapping the pin definitions in the program it works of course. i could still use some help though if anyone has the time. i've got a main idea on what to do, just need help trimming it up
If your issues are specific to what you're trying to do I would suggest starting a new thread in the BASIC Stamp Forum with the details of what you're trying to do, what you have so far and where you're stuck.
Thanks Chris once again, your code is great as always!
I have a question if you don't mind.
There's a code:
secs01 VAR secs.LOWNIB
secs10 VAR secs.HIGHNIB
.
.
.ampm VAR hrs.BIT5 ' AM/PM Flag Bit
clockMode VAR hrs.BIT7 ' 12/24 Hour Mode Bit
While I understand what these operators do (substitute to tens and digits, and put a bit at specified place in byte) in this particular case, I'd like to know how to do same operations, without using these commands?
Could you be more specific about what you mean? Within the hours register specifically these bits are used for the mode and flag, so the problem is that if you just read the register for hours you may not get what you expect depending on the status of these two bits. One way of reading and writing individual bits within a variable is called masking. With masking you can set or clear any bit within a variable. For example, if you have a variable (byte) 010011 and you only want the low nibble you could AND the value with the following mask: 001111. The resulting value would contain bits set that were 1 in both the original value and the mask. So in this example your output value would be 11 or 3. This is one way of reading the bits you want. You could read as many or as few by changing the bits set in the mask.
You can also set or clear bits. If you have 010011 and you want to set bits 2 and 3 (currently 0) you can say 010011 OR 001100. Now you'll have 011111. Also if you want to clear bits you could say 010011 AND 111100 and you would effectively clear the lower 2 bits (010000). I hope this helps. If you have additional questions please let me know. If I missed the mark on what you were asking, please let me know.
I'm asking a bit more information about LOWNIB & HIGHNIB commands and BIT.X mostly how they can be replaced with plain operators for better code understanding.
For example, if I understood properly,
secs01 VAR secs.LOWNIB
secs10 VAR secs.HIGHNIB
Means secs=secs10*10+secs01
right?
But this is not plain operator, as it seems, i.e. it means that each time secs01 or secs10 changes, secs gets automatically updated, so code needs heavy modification to avoid usage of these statements ?
I want to deeply understand the code, how it works, not just use it, so these bitwise operators confuse me, so I'm asking, whenever they can be replaced with simple math commands, to improve readability of code?
I understand the need for readability, however one might argue that in their current form they're more readable the way they are and that breaking them down would make them appear less intuitive. But that's another conversation...
The whole process is further complicated by the fact that these values are stored in BCD, not decimal. I will reply more tomorrow. :nerd:
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
So I'm running the DS1302_Demo and I'm interested in modifying it a little bit. I connected an LED and would like the LED to light up at a certain time... Say, whenever it's nine o'clock (am or pm) I want the LED to light up. I currently have the LED connected to PIN 15, so I tried something like:
If hrs = 10 THEN (for 10 o'clock)
HIGH 15
ELSE
LOW 15
ENDIF
However it's not working. I think it's something to do with hrs not actually being stored as 10, since it's HEX2, but I'm not sure about that, or where would be the place to put this code into the DS1302_DEMO code.
Thanks for the help!!
The problem is the literal value and the perceived value are two different things. In BCD each digit is considered to be 0-9. However if you simply increment the value you will eventually get illegal values. You're checking for a 10 (Decimal), but as you mentioned, the data is displayed using HEX2 because it treats each digit separately. The only thing you can do is put a $ in front of your 10 ($10) and then it will detect when the hours are at ten o' clock. If you add the dollar sign to your value above your LED should come on at 10 and stay on for an hour. Remember, the HEX2 formatter just causes the 2 digits to be treated individually.· I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
Post Edited (kemicro) : 7/6/2010 7:35:04 PM GMT
I would say I would need to see the code and schematics to help you isolate that kind of problem.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
I'm new to Stamps. I saw your thread about the date, time and seconds and was wondering how you made that program. Is your code available to look at? Thank you for your time.
Art
Got my DS1302 and crystal in the mail, and had some time to play today ...
Demo works fine for me, and was able to put together a separate program to set time/date/day ect, then just incorporate the functions to get and display the time,ect in my main program. Was kinda wierd , tho - I hooked up 2 AA batteries to store the time, and noticed some wierd results in the display awile later, gibberish in the time display, or incorrect numbers. Of course, the last thing I tried was disconnecting the batteries and assumed the IC or crystal or connections were screwy . Disconnected the 2 AA's and everything works fine( think I just have a flaky connection between B.B. and bateries), except for the below...
Just one thing I am having trouble with - and was wondering if you could toss me a hint on how to display everything ( Day, MM/DD/YY, HH:MM [noparse][[/noparse]SS] , AM/PM ) on a single line in debug window using SEROUT ?
Trying to solve it myself, but aggggh I ...am...drowning.....in Cisco , electronics and Maths and my brain cant seem to grasp the solution
Edit: hah! I got it -
sorrry to mess up your thread, Chris . Took a bit of work to string it all together at the exact position I wanted in the debug, but it works wonderful now! The loop with the "day" and the AM/PM stuff threw me for a ..errr loop, but its all good.....
It now starts at 0,5 in the debug, prints DAY mm/dd/yy hh[noparse]:mm:[/noparse]ss AM/PM
Whoopee!
AHHHH the joy of discovery!
Aloha,
Robert
Post Edited (Robert@HCC) : 1/19/2006 9:16:01 AM GMT[/QUOTE]
I had the same problem before I connected a "good" battery to pin 8 on the DS1302. You might attach your code and a schematic. That way we have a chance to see what could be causing your time reset.
I've just bought some DS1302 chips from Parallax in order to create a solar tracking system based on real time calculations.
For my project I have used the propeller proto board and I have build the following time circuit using the DS1302, a crystal 32.768 khz and a 3V lithium battery CR2032.
The code I have used is the"DS1302_full-demo.spin" and it is based on "DS1302_full-demo" Object.
Runing the code I can setup the DS1302 chip. I can give the Date and the Time successfully.
The DS1302 keep the given time even after a current outage.
However when I execute the above code, the result on the serial telminal screen, shows that the Clock stick at the same time (the time that I give in the setup).
Can you give me any idea why does it happens? What is going wrong?
P.s Thanks for this thread and the given codes! It gives the best explanation about the DS1302 and BasicStamp. I look forward to see from you a similar presentation (like this thread) for the function of DS1302 using the propeller!
Instead of this crystal I use a "Hosonic 32.768 B221" Ctystal.
Unfortunately I hadn't realized the necessity of the crystal when I ordered the DS1302 chips and I can't found these crystals here in Patras. I think that I have to make a new order from parallax.
I have this demo working with an LCD. I am planning to incorporate it into the Home Monitoring system I'm working on to place a Time and Date stamp on a PINK and have a webpage record the last Date/Time a particular sensor state is changed.
Question: What's the best logic regarding placing this code and and having the remainder of the project's code access it when Date/Time data is required, but continue to run? I don't need to display the Date/Time continually. I only need to have it when it is requested. I noticed the "place your main routines here" note in the template but my main code uses 5 slots so I'm not sure if it would be practicle to place all of that code in this loop. All in reference to multiple slots on a BS2e.
My thought is to use this code as part of an "initialization" in Slot 0 that will run once in the beginning when the Stamp is powered up to set the Date/Time. The DS1302 will run in the background to maintain the Date/Time. The Main code would then "loop" from the last Slot to Slot 1 to keep the program running.
Then, when a sensor state is changed, I would have to to the following:
GOSUB to the Get_Time subroutine to read the DS1302
GOSUB to the Show_Time subroutine to update the STAMP variables
SEROUT the STAMP's Date/Time data to Pink variables.
Is that a reasonable approach? Or could I delete the Show_Time routine and go right to the SEROUT?
falcon
Embarrassingly, I happen to have a DS1202 (not the DS1302) that I want to finally use and this code seems to be fine for it. I think it was in one of my first order from Parallax.
( http://nutsvolts.texterity.com/nutsvolts/201002?pg=26&search_term=clock#pg26 ) on your Clock.
Looks great, and I want to use it in a project I'm working on, I downloaded the BS2 code and related content from Nuts and Volts; but before I run it for the 1st time, I got 2 questions;
#1) On the Schematic "C3- 0.1uf" connected to 5V and Ground, Under the MAX7219; I'm a bit confused, do I connect C3 to the MAX7219 5V or is it part of the Power Suppply?
#2) On the LM386, can I replace "C8- 0.05uf" with a diff CAP, like a "0.068uf" or something near +/-
Thanks
- C3 was intended to be a bypas cap placed close to the MAX7219. It's power pins will connect to the same supply pins as the cap, but being close to the MAX7219 will help filter noise in the supply created by the MAX7219. I should have notated the placement of that cap rather than just left it floating. Thanks for the feedback.
- You can change the value of that cap to a .1uF and the resistor to a 10 ohm if you prefer. That circuit if basically a snubber circuit which prevents high frequency oscillation.
I hope this helps.done with the final pieces. I used a 0.068uf Cap on C8, added an LED to indicate power, a diode on the in of the 7805 power supply for polarity/safety reasons, and it works GREAT.
Will add bottons, other sensors, ect, .... thanks again for the quick reply and nice project. :nerd: :thumb:
EDIT: for some reason i was able to re-download the program and it worked? i was able to set the time, no issues. but then when i pressed 2 to look up the time, it still said 0 for all. it didn't save what i did.
second edit: ok, i'm a complete idiot. i had the data i/o and the clock pin backwards. after swapping the pin definitions in the program it works of course. i could still use some help though if anyone has the time. i've got a main idea on what to do, just need help trimming it up
I have a question if you don't mind.
There's a code:
While I understand what these operators do (substitute to tens and digits, and put a bit at specified place in byte) in this particular case, I'd like to know how to do same operations, without using these commands?
Could you be more specific about what you mean? Within the hours register specifically these bits are used for the mode and flag, so the problem is that if you just read the register for hours you may not get what you expect depending on the status of these two bits. One way of reading and writing individual bits within a variable is called masking. With masking you can set or clear any bit within a variable. For example, if you have a variable (byte) 010011 and you only want the low nibble you could AND the value with the following mask: 001111. The resulting value would contain bits set that were 1 in both the original value and the mask. So in this example your output value would be 11 or 3. This is one way of reading the bits you want. You could read as many or as few by changing the bits set in the mask.
You can also set or clear bits. If you have 010011 and you want to set bits 2 and 3 (currently 0) you can say 010011 OR 001100. Now you'll have 011111. Also if you want to clear bits you could say 010011 AND 111100 and you would effectively clear the lower 2 bits (010000). I hope this helps. If you have additional questions please let me know. If I missed the mark on what you were asking, please let me know.
For example, if I understood properly,
Means secs=secs10*10+secs01
right?
But this is not plain operator, as it seems, i.e. it means that each time secs01 or secs10 changes, secs gets automatically updated, so code needs heavy modification to avoid usage of these statements ?
I want to deeply understand the code, how it works, not just use it, so these bitwise operators confuse me, so I'm asking, whenever they can be replaced with simple math commands, to improve readability of code?
The whole process is further complicated by the fact that these values are stored in BCD, not decimal. I will reply more tomorrow. :nerd:
This piece of code should be enough?
and all variables declared should be BYTE type?