Weird behavior of BS2P40 when reading DS1302
LuXo12
Posts: 31
in BASIC Stamp
Happy Holidays!
I'm having some problems reading data from the DS1302 time chip and I was hoping someone with more experience could point me in the right direction.
Here is whats working in my project;
I can set both time and date with a pushbuttons connected to the Basic Stamp
I can display the time and date with 4-7 segment displays connected to the stamps via shift registers.
The issue I'm has to do with the 7 segment displays, roughly about every second they flash (loose their values) and go back to displaying the proper time/date.
Oddly the debug terminal is doing the same thing. all of the variables holding (hours, minutes, seconds, year, month, date) get reset to 0, and immediately return to the proper value.
Attached is my code and gif
I'm having some problems reading data from the DS1302 time chip and I was hoping someone with more experience could point me in the right direction.
Here is whats working in my project;
I can set both time and date with a pushbuttons connected to the Basic Stamp
I can display the time and date with 4-7 segment displays connected to the stamps via shift registers.
The issue I'm has to do with the 7 segment displays, roughly about every second they flash (loose their values) and go back to displaying the proper time/date.
Oddly the debug terminal is doing the same thing. all of the variables holding (hours, minutes, seconds, year, month, date) get reset to 0, and immediately return to the proper value.
Attached is my code and gif
Comments
Edit: You can easily prove (or disprove) that hypothesis by putting a beep prior to your DO.
-Phil
Do you have a schematic especially showing what it wired to the Main and Auxiliary I/O pins?
Also, what exactly is your program supposed to do?
It would help greatly if your program was formatted and documented.
PS,
I thought this code looked familiar. You did something very similar 2 years ago.
The DS1302 only stores the last two digits of the year in the 7th byte. There is no provision for the century.
here is a list of what "new" version of this code will do:
Announce time every full hour of the day, (example "It's twelve o'clock"),
I added alarm clock function, this project will play a sound track of your choice from an SD card using the MP3 modules.
Another program in slot 0 of the BS2P40 will convert infrared signals from Sony TV remote to X10 commands
pressing the power button on the tv remote will prep the stamp. Voice generated using text to speech software will play back from the MP3 module and instruct the user to enter the X10 house code, X10 unit code and turn on/ turn off command. if you interested i will post a video on how it works.
Last thing I'm planing of adding to a project is a DTMF decoder. This will be used to allow me to call in and control x10 devices in my house.
This is almost complete should post a code for that function later today.
Actually, it sends 8 bytes in burst read mode.
Burst writes to the clock must be eight bytes. However, when doing a burst read, it sends as many bytes as the master clocks in, beginning with register (or RAM) zero. Typically, one reads seven clock registers.
Now, it does have a note about needing 8 bytes for Burst Write.
Also, I noticed that much of the RTC code resembled the code from the DS1302 AppKit documentation.
I did examine the code more closely and found some oddities such as INx is being used to detect push-buttons even though there are 3 pushbutton PIN variables.
Also the RTC /RST pin should be a PIN and not a CON and placed with the other I/O pins, and the RTC Clock and Data pins aren't even defined.
Currently the RTC code is using the same pins as the 595 Shift Register. Also, I am assuming that the 595's are cascaded just like in StampWorks Experiment #23.
In the Main Loop the RTC is read and sent to the screen and next it is read and sent to the 7 segment display.
Why read it twice and the Out_595 routine uses display values that were never retrieved so it will only display whatever was there before.
By the way, what do those "display" values mean because we don't know how the 595's are wired to the 7 segments.
Again, the code is very confusing because it's unclear what variable does what and many of them seem to have multiple uses, especially Temp.
In Show_Alarm, why is Day being used as a Looping Variable?
And then in Enter_Time, you are again sending Output to the 595 but it's unclear what Display Values it's using.
In Program_Time and Program_Alarm, there are a stream of variables which keep repeating except for a few values change.
Why is Get_7_Segment_Display_Digit_Output_Value called LCD_Constants when they will be going to a 7 Segment Display and not an LCD?
Also be aware that in FREQOUT the BS2p uses a duration value of 0.265 ms instead of the 1 ms that the BS2 uses. The BS2p uses 3.77 Hz instead of 1 Hz.
The BS2p uses a PULSOUT Duration of 0.8 us instead of the 2 us that the BS2 uses.
All of this is the BASIC Stamp Manual.
Did you by chance run any test programs to be sure that your wiring is correct?
I also making a schematic of my project, i will upload it when its completed.
You are right for pointing out my RTC code resembles the DS1302 AppKit documentation, as it was my main source, for getting it to work.
I'm able to get the time and date to show up both in the debug terminal and on the 7-segment displays, so I the code works (even if it looks like a mess at this point).
Calling of the subroutine GOSUB ReadRTCBurst twice in the beginning of the loop was left there by mistake (Fixed).
The Out_595 routine relies on three other sub routines called timecon, datecon and LCDcon. The timecon/datecon routine get the hr/min, month/date high nib and low nib value of each variable and forward it to the LCDcon routine. LCDconconverts the decimal values (0-9) it receives to values that the shift registers need to display a proper number using a lookup table.
so to show 1 on the 7 segment display i need to send decimal value 183 to the first shift register. Timecon/datecon are responsible for preparing the Disp1, Disp2, Disp3, Disp4 variables used in the Out_595.
Did you by chance run any test programs to be sure that your wiring is correct?
Yes, the project is basically a collaboration of smaller project put together.
I have program for testing the different components of my project individually without changing the wiring. There are programs for testing the DS1302 module, MP3 module, DTMF decoder, X10 pwerline interface PSC04, and four 74HC595 shift registers that are daisy chained and drive the 7 segment display. Most of the "test" programs are from Nuts & Volts (shift registers, X10) or parallax site (DS1302).