More...

Time is an illusion. Compile time - doubly so.

Posts from: November '10


PIC 3

The coolest project I've created. EVAR.
50+ months.
Gardening meets PIC assembly.

Where did it all start...:

Image
Meet the Poinsettia. A photo-periodic plant, native in Mexico. Suitable for home, but it needs 14 hours of continuous darkness (starting from October), so it can "sense" winter is coming and trigger blossom.

And it looks good when it does:
Image
:)

Poinsettia meets the student-programmer day/night cycle:
Don't try to figure out any order or logic — there ain't any.
Image

In result:
Poinsettia stays green, three years in a row. Since we rarely turn off the lighting here before midnight, the biological clock of the poor plant gets totally screwed up.

I've read from several places in the net, that this problem can be alleviated by placing a large box over the flower in the late afternoon, and lifting it up in the morning. It just needs 14 hours of "night".

However, this needs manual intervention and it's not my taste, really. Waking up early is a no-no for me.

Meet the PIC microcontroller:
Image
Capable of running all kinds of peripherals and electronics. I got the PICKit 2 starter kit - a programmer, a PIC16F690 chip, a Low-pin count demo board, and some software to learn&use all this.

Applying some soldering, relays, wiring...:
Image
We can now drive a DC motor back and forth. Yay.

Meccano building kit:
Image
Generic metal building set. Unleash your imagination. For starters, we did one of the models in the book:
Image


Let's build a crane:
Image.Image



Programming:
Image
Pure Assembly. Everything else is shit.


A box... using plain wires:
Image.Image
Since a cardboard box that large (32х38х38cm) would be too heavy - usually over 500 g - I built a cage using wires, and wrapped it up in black nylon - the whole box is less than 100 g!


Mounting the crane:
Image.Image
Works surprisingly well. Designed for up to 7 Richter (like, really!)

So finally, the Thing is completed! Run for your lives!

It:
Image.Image
Image.Image
Image.Image
Image.Image
Image

Well. So you are probably a bit confused over here. The idea is like:
The PIC is programmed to run busy loop, counting the time that way. Turns out to be fairly accurate.
At 5pm, the "box" is moved down, so it covers the flower and provides darkness.
At 7am, it is lifted back up.

See this clip of the whole thing in action: Youtube

This son of a bitch is really working. Two weeks now.

On a side thought, I really learned one thing while working on this project: if you set your goals too high, and pursue them by any means that are out of your technical reach, you're going to fail. You really need to keep focused on the important things. It is vital to define your target correctly, and be ready to adjust your standards of success lower and lower as the project wears on. Some ideas aren't really worth pursuing. Consider:

* Being battery-powered (I reviewed all kinds of power sources, 4.5 volts, 9 volts, 4xAA rechargeable, even a LM7805 combo came to my mind...) (didn't need any of that after all. The Thing is inside a fucking house! You can really use a 5V adapter. It's lame. But it works™.

* Detecting the movement endpoints - since I had this current-sensing circuitry anyway, I could've sensed when, e.g., while moving the box up, it comes to halt at the top point, as the current through the motor increases sharply. I had even a more wild idea for the downward movement. Here it is: move the box, in a timed fashion, a bit more than it should be needed. Then start to pick it up. When the slack of the rope is consumed and it starts to pull the box, the current will rise, so stop here. (Of course, got rid of that idea, too. This is far too buggy and fragile. Calibrated timing is all you need.)

* Keeping track of time (throughout the day) - I've came up with all sorts of ideas. For example, I could've used an precise timer, which would trigger interrupts on the PIC. The interrupts would wake the microcontroller from sleep (and sleeping is for... conserving the power from the battery - see point 1).

* Don't use the internal clock of the PIC - use an external quartz resonator instead...

* Various battery efficiency ideas, e.g. - don't run the PIC at 4 MHz; use lower speeds. 32 kHz is sufficient, and the PIC is far more efficient that way.

* All other kinds of crazy ideas, basically avoiding to keep track of the time with the PIC.
(You'd wonder why was all that fear. Well, the datasheet says that the PIC achieves its best clock accuracy, "only" 1% of rated MHz, when we assume room temperature and 5V power supply. But, I thought, even there, the error is huge - we're talking about ~15 minutes per day! Well, with some calibration, the PIC becomes fairly good at tracking time. My current performance is being merely 10 seconds too slow per day, and I can calibrate it better if I want to. Anyway, the plant doesn't care.)

I did implement a few debugging things though. For example, I can trigger the movement, up or down, by holding the button of the demo board for a while - the type of operation being determined by the amount of time I kept it pressed. Another function I coded is that I can ask, "PIC, tell me what time is it", and it would show me. In 4-bit binary. Minutes are displayed like this: first, it prints M div 5, then M mod 5. Another thing that kept me busy for a while was an actual hardware bug that developed out of nothing, some time after I finished my first soldering two years ago. The bug was that the motor refused to turn in one of the directions, and the relays clicked wrong during that. More precisely, one of them wasn't clicking at all. When you touch the pins at some specific place of the board, it suddenly works all right again. Of course, it turned out to be bad soldering. There are no miracles in electrical engineering - only weak joints. But you should've seen what it is like to debug hardware. You still think that text-based gdb debugging is painful, ugly and obsolete? Meh.

P.S. I uploaded the source code of this thing: /code/my_projects/PIC.


Posted in category Hardware -- clock 18 Nov 2010, 00:54, 0 comments

Language:

bgБългарски
enEnglish


Categories:

Meta
Hardware
Technology
Fun
Open source
Interesting
Hiking/Trips
Stuff
Programming
Music
Images
Photography
All


Archive:

+ 2008 (9)
March '08 (2)
April '08 (2)
May '08 (2)
October '08 (1)
December '08 (2)
+ 2009 (8)
January '09 (2)
March '09 (1)
August '09 (2)
September '09 (1)
November '09 (1)
December '09 (1)
+ 2010 (9)
January '10 (1)
April '10 (2)
June '10 (1)
July '10 (1)
September '10 (1)
November '10 (1)
December '10 (2)
+ 2011 (10)
January '11 (3)
February '11 (1)
August '11 (2)
September '11 (2)
October '11 (2)
+ 2012 (14)
January '12 (3)
March '12 (1)
April '12 (2)
May '12 (3)
August '12 (1)
September '12 (1)
November '12 (1)
December '12 (2)
+ 2013 (1)
March '13 (1)
+ 2014 (3)
September '14 (3)
+ 2015 (5)
January '15 (1)
March '15 (3)
May '15 (1)
+ 2016 (4)
June '16 (1)
July '16 (1)
November '16 (1)
December '16 (1)


Last comments:

30 Mar 2017, 13:59 by antfarmer
26 Dec 2016, 17:52 by Private
19 Dec 2016, 23:01 by ицаци
16 Dec 2016, 19:50 by Антон
8 Dec 2016, 01:23 by anrieff
8 Dec 2016, 01:06 by Николай


Valid XHTML 1.0 Strict

Blogroll:

linkJoel on Software
linkRidiculous Fish
linkXKCD blag