Ice Tube firmware - Drift correction with Auto DST, Dimmer

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
brand
 
Posts: 12
Joined: Sat Dec 31, 2011 4:11 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by brand »

It continued to gain time at the maximum setting, so now I'm settling in on the calibration.

With the stock firmware, it was losing about two seconds a day. With this version, it seemed to be losing about four seconds a day before you sorted the drift correction bug out. Given that the drift correction can handle about 12 seconds a day, I'm not to bothered by that. Besides, I don't really want to mess with the crystal for the same reason I don't want to mess with the dimmer resistor -- I don't want to screw with a working board. : - )

As you say, you can argue the sign either way. From a naive perspective, positive should go faster and negative should go slower, but if you know that it's the number that's modifying the comparison baseline once an hour, then it makes sense the way it is (negative goes faster, positive goes slower). Changing OCR2A = DRIFT_BASELINE + drift_corr; to OCR2A = DRIFT_BASELINE - drift_corr; is a simple enough mod.

Thanks again.

Take care,
brad

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

I think the drift correction setting should be being positive to increase the speed, to speed up a slow clock, and negative to slow the clock down. That seems more intuitive to me.

William

User avatar
brand
 
Posts: 12
Joined: Sat Dec 31, 2011 4:11 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by brand »

So, I finally got the thing shipped off to my brother-in-law -- only a month and a half late for his birthday.

A couple of notes:

I was playing with the photoresistor. I didn't look at the schematic for the clock, but I'm assuming the photoresistor is half of standard two-resistor voltage-divider. I was getting anywhere from about 140 ohms (dark) to 28K ohms (very light) out of the photoresistor. The difference between a 1K ohm resistor and a 22K ohm resistor on the other side of the divider is about an extra .5 volt delta.

I'm not too confident in my math (yeah, it's simple, and I'm good with numbers, but analog electronics is a new area for me), so I tested it empirically with an ATMega168 as well.

I also wrote some user documentation for the specific sequence of commands on this firmware (I added a little Easter egg before the code version), just in case anyone follows this thread and is also making it for a gift. The file is attached in raw text format, since the forum won't accept open document. A mildly formatted version is here: http://www.drbrad.org/IceTubeDoc.odt
Attachments
Doc.txt
(7.16 KiB) Downloaded 335 times

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

According to the Adafruit web site, the photocell is roughly 5-10K ohms in light, and 200K ohms in the dark. I'm wondering what/how you were measuring since you seem to have gotten the inverse of this.

Let's keep it simple. If the photocell is 10000 ohms when exposed to light, and the resistor is 1000 ohms, that's 11000 ohms total. We know the supply voltage is 5 volts. Ohms law gives us 5/11000 = 0.00045 amps or 0.45 mA. The drop across the resistor is 0.00045 times 1000 = 0.45 volts.

If the photocell is 10000 ohms and the resistor is 20000, the total is 30000. 5/30000 = 0.00016 A. The drop across the resistor is now 0.00016 times 20000 = 3.2 V. That's a difference of 2.88 volts, not 0.6 volts.

In the dark, if we assume 200,000 ohms, with a 1000 ohm resistor, the current is 5/201000 = 0.000025 A. The drop across 1000 ohms is 0.025 V. With a 20000 ohm resistor, the current is 5/220000 = 0.000023 A. The drop across the 20K resistor is 0.000023 x 20000 = 0.45 V.

I used a 20K ohm resistor because with 1K the circuit was not as sensitive as I would like.

Here's a tutorial on how photocells work:
http://www.ladyada.net/learn/sensors/cds.html

User avatar
brand
 
Posts: 12
Joined: Sat Dec 31, 2011 4:11 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by brand »

I just double-checked, and you're right; I've got the values backwards (I misread my notebook when I put up my previous post the other night). However, the values are correct. I measured the resistance with a multimeter, with my thumb over the photo-resistor for the dark condition (~28K ohms) and shining a reasonably bright LED flashlight on it (from about 1/4 inch away) for the light condition (~140 ohms).

So, okay, I'm not really here for an argument (this is "being hit over the head" lessons, right? : - ), but I'm learning stuff here, and someone playing with the photoresistor may find this useful someday...

The schematic at the bottom of this page http://www.ladyada.net/make/icetube/design.html shows that the circuit is a straight voltage divider with the light sensor on the ground side. We're doing the same math, but I think of it as

V-out = V-in * [Photoresistor / (R1 + Photoresistor)]

For R = 1K, that's about .6v (light) to 4.8v (dark)
For R = 20K, that's about .04v (light) to 2.9v (dark)

I set up a simple test rig that outputs the result of the analog-to-digital comparator (ADC) and the voltage (ADCsample * (5.0 / 1024.0)). The first picture below shows the rig with a 22K ohm resistor (ignore the LEDs and DIP switches).
IMG_0022.jpg
IMG_0022.jpg (120.14 KiB) Viewed 3262 times
The next picture shows the output for the dark condition (with my finger over the sensor), at 2.35v.
IMG_0023.jpg
IMG_0023.jpg (121.47 KiB) Viewed 3262 times
The output for the bright light condition was 0.02v.

It's nice when the math sorta works out, but that would be about 19.5K ohms and 88 ohms off the photoresistor if my math is right:

Photoresistor = R1 * (Vout / (Vin - Vout))

Either that, or that's a 34K ohm resistor, but I measured it with a multimeter and got close to 22K ohms. I'm not sure what's going on there.

I did the same thing with a 1K resistor and got 4.75v and .63v, which is right in line with the calculation above. I'll spare you the pictures, but I have them : - ).

Finally, here's a shot of the light condition with the multimeter attached to the photoresistor showing 164.5 ohms.
IMG_0030.jpg
IMG_0030.jpg (106.88 KiB) Viewed 3262 times
I got about 14.3K ohms with this particular set up for the dark condition.

When I was holding the contacts to the photoresistor with my fingers (instead of the clips), I was getting the values above. I'm pretty sure this is because the clips are on dodgy cables.

So, despite a broader range of voltages (empirically as well as theoretically) with a 1K ohm resistor, you were seeing better sensitivity with a 20K ohm resistor.

My hypothesis here is that I'm testing way too far up on the bright end of the scale (probably up to 10,000 lux), and you were seeing better sensitivity in the dimmer conditions you were interested in (0.2 to 80 lux?), which would make some sense, as the resistance isn't linear.

Comments?

thinwing
 
Posts: 32
Joined: Thu Feb 02, 2012 1:03 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by thinwing »

Ok I downloaded code and installed photocell and 20k ohm resistor...I am new to usptiny...I see a few files in Williams download...is it the ivhex I want to load for the ice tude mod ,and what is avrdude command statement?...thanks kpc

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

Hi, kpc,

Yes, iv.hex is the file to load.

This should do it:

Code: Select all

avrdude -c usbtiny -p m168 -U flash:w:iv.hex
I use an Arduino ISP to program chips for my clock, so I use this:

Code: Select all

avrdude -c arduino -p m168 -P COM10 -b 19200 -U flash:w:iv.hex
You can also edit the makefile and use "make program" to load the code but that's probably more than you want to get into at this point...

If you have any problems let us know and we'll try to help.
William

thinwing
 
Posts: 32
Joined: Thu Feb 02, 2012 1:03 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by thinwing »

Thanks William the gf is complaining how bright the icetube is at night and how it keeps her up at night...I keep finding stuffed animals placed in front of clock as a light dam...hope the autodim does the trick..regards kpc

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

That's too funny! I had the same issue but it was bothering me, not my spouse. That's why I changed the brightness level settings so they could be adjusted lower. The lower limit may be too low now for your tube but at least you have the option. I find with one tube I have that the segments get uneven at really low levels at first but that they seem to even out over time.

thinwing
 
Posts: 32
Joined: Thu Feb 02, 2012 1:03 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by thinwing »

Ok i am flashing the chip now,tube off,9v to board,jumper off the usb tiny...kpc

thinwing
 
Posts: 32
Joined: Thu Feb 02, 2012 1:03 am

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by thinwing »

firmware loaded ok,clock is working as advertised,..I thru in a drift correction of -22 also ...autodim working and next is to cobble a neat 3 pin header for side of board next to fuse...i plan to drill thru board with pcb drill,carefully grind away ground trace at that location and hysol in a three pin header at 90 degrees.Gps module will reside in the window sill with nice shielded cable running to clock and plugging into header.thanks for the programming help...I am now thinking of building a bulb dial!!! sinc kpc

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

Cool - glad it's working! Nice idea to add a connector for the GPS. I found the Adafruit GPS module to be so sensitive that I just stuck it on the back of the clock with foam tape. In my single story wood frame house it's impossible to find a location where it doesn't acquire enough satellites to provide time data.

User avatar
grumpygasbag
 
Posts: 33
Joined: Fri Mar 30, 2012 5:28 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by grumpygasbag »

Hi,

I installed William's firmware (THANK YOU!!) using a DAPA programmer and AVRdude which kept giving me verification errors (waiting on a USBtiny programmer to arrive) but for the most part it seems to be working nevertheless.

The hack for brightening the last digit works perfectly (it was quite dim before)!

The autodimmer is also working perfectly (R4 = 22K) using a photo-resistor I got here in Australia (light value about 12K and dark value about 150K).

I've installed a pin header for the GPS underneath the case. I used the 4-pin power socket off an old PC floppy drive, still attached to a small section (about 1.5" x .75") I sawed off the circuit board but with all the tracks disconnected. I drilled a hole through that bit of the board to mount it using the bolt/nut already coming out of the bottom of the case. This pin header is connected to the main board with a short length of screened cable passing though a small hole I drilled in the bottom of the case. One of those PC audio cables (that usually connects to the CD drive) fits the pin header perfectly if you trim off the bits of plastic that make it specific for CD drives. On the other end of that is a socket into which can be plugged a GPS "mouse" - I already have a couple of BR-355 receivers connected to other nixie clocks. Only problem is the GPS function doesn't seem to be working. I can set it to on in the menu and set my zone ok. The GPS receiver is locked onto the satellites ok. But after an hour it still hasn't caused to clock to correct the time and the latitude says -H.H.H.H.H.H. and the longitude says -H.H.H.H.H.H.H.

Any ideas? I've triple checked all the connections and they are exactly as described on the GPS mod page. The power is definitely ok otherwise the BR-355 wouldn't have a flashing light. And I checked the data connection to pin 2 of the AVR and that is also close to zero Ohms from the socket into which the mouse is plugged so the data should be hitting pin 2 ok. As far as I know the BR-355 uses exactly the same protocols as the GPS module from Adafruit. It's certainly working fine for my other clocks.

Thanks in advance for any suggestions.

John

User avatar
wbp
 
Posts: 260
Joined: Mon Mar 07, 2011 1:18 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by wbp »

John,
What baud rate is the GPS module set to?
William

User avatar
grumpygasbag
 
Posts: 33
Joined: Fri Mar 30, 2012 5:28 pm

Re: Ice Tube firmware - Drift correction with Auto DST, Dimmer

Post by grumpygasbag »

Default 4800, as far as I know. That's what the other clocks use.

Locked
Please be positive and constructive with your questions and comments.

Return to “Clock Kits (discontinued)”