Pages: [1] 2   Go Down
Author Topic: [Advice needed] Building a small BCD clock.  (Read 3123 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Introductions are awkward, straight to business:

I need some advice on how to control 14 leds, with the smallest possible microprocessor. I'd rather not buy an arduino mini just for this project, as this is a school project. I haven't written any code yet, but I was thinking I could just count the time within the loop.

I discovered that it is possible to shrink your projects, by uploading your sketches into single chips, such as the ATtiny85. Now that's small enough, but it only has 6 I/O pins, and I need to control 14 leds. Unless I can find a 14 I/O chip that's relatively small, I'm going to need some help from you guys. I googled around and read something about an LED matrix, but I really don't get the idea, since it seems to require the same amount of outputs anyway. I guess it makes the code clearer.

TL;DR: What's the simplest way of controlling 14 LEDs with the smallest possible configuration?
« Last Edit: September 26, 2012, 06:04:46 am by iDroid » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26443
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps.
14 resistors, 14 LEDs.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps.
14 resistors, 14 LEDs.
A board to mount the stuff on.  And access to someone else's system with a serial line to program it. Easier if the atmega328 already has a bootloader programmed.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps.
14 resistors, 14 LEDs.


Thanks, but isn't the the ATmega series quite large, compared to Attiny? ATtiny 40 seems to have a max 18 I/O pins and it's definetely smaller. Do I need the crystal and caps if I'll end up using this one? What about the program to turn the leds on, can you suggest anything "smoother" than a bunch of if - structures?

A board to mount the stuff on.  And access to someone else's system with a serial line to program it. Easier if the atmega328 already has a bootloader programmed.

Right, that's pretty obvious. I've got a friend who has an Uno, so I can program the chip with it, right?
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 144
Posts: 5340
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps.
14 resistors, 14 LEDs.


Thanks, but isn't the the ATmega series quite large, compared to Attiny? ATtiny 40 seems to have a max 18 I/O pins and it's definetely smaller. Do I need the crystal and caps if I'll end up using this one? What about the program to turn the leds on, can you suggest anything "smoother" than a bunch of if - structures?

The smallest one with 14 pins would be an ATtiny4313.

PS: You don't really need the crystal, they work just fine with their internal clock. The only time you need an external crystal is when you need accurate timing for, eg. serial communications.

If you want a smaller AVR chip (Tiny84 or Tiny85) then you'll need an external 16 channel LED driver. I think the smallest 16 channel chip has 24 pins (eg. TLC5925).

Right, that's pretty obvious. I've got a friend who has an Uno, so I can program the chip with it, right?

You can do it that way So long as he doesn't mind you pulling it apart. The best way to work with bare chips is to get an "ISP Programmer". They cost about $12 and when you have one you don't lose any flash memory to bootloaders, etc.

PS: The ATtiny85 only really has five usable pins. You can use six pins but after you reconfigure the reset pin for I/O you can't upload any more software without a special device to configure it back again.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Valencia, Spain
Online Online
Faraday Member
**
Karma: 144
Posts: 5340
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PPS: You could also do it with an ATtiny84 and a technique called "charlieplexing". It allows you to control (eg.) six LEDs with only three pins but it's tricky to get right.

See: https://en.wikipedia.org/wiki/Charlieplexing

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using charleplexing, you can control up to 20 LEDs with 5 pins. This would be your best bet. I recently put some code up on Github that makes it relatively painless: https://github.com/marcuserronius/ChuckPlex/tree/1.0

… as for controlling the LEDs, I'd make arrays organizing the relevant LEDs. Split the time up into separate decimal components, and extract the extract the place values of the ON bits from each, use them as indices for the LEDs array, i.e.:
Code:
int digit1[] = {1,2};
int digit2[] = {3,4,5,6};
int digit3[] = {7,8,9};
int digit4[] = {10,11,12,13};
[…]
for(i=0;i<4;i++){
  if(bitRead(timeDigit2,i){
    // turn on LED digit2[i]
  }
}


Something like that, maybe. If you go with multiplexing the LEDs, this *might* end up causing too much flicker, in which case you could build a list of LEDs to turn on and cycle them until the next time the time changes.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As you are building a BCD clock I would use an ATTiny with at least 8 outputs and arrange your leds on a 4x4 grid (with gaps where you dont need LEDs)

Then you can use 4 of your outputs for your rows and four for you columns and you have an easier solution than charlieplexing. You would need to row scan the rows of the 4x4 matrix but there are loads of tutorials on how to do that on these forums and on the net.

Something like
     X           X
     X      X   X
 X  X      X   X
 X  X      X   X
Hours   Minutes

HTH
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 46
Posts: 2865
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An RC oscillator isn't going to make a very accurate clock... Not at all. Go read the notes on RC frequency vs temperature and supply voltage variations. What you propose to do would be neat... as long as it didn't have to keep time.

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, hope this post isn't too old yet, because OP is here to deliver... Somewhat.

So I got this set up on a breadbord with the Arduino Uno, just to see how the code works. I'm using the millis() function to count milliseconds from the time when the program started. Every 1000 milliseconds, it adds one to seconds, every 60 seconds it adds one to minutes and so on. Each LED is connected to it's own digital pin on the Uno and lights up accordingly with basic if functions. Right now there's only one button to set minutes on digital pin 0, but I plan to add one for hours as well when its time to shrinkify this project to the ATtiny2313. The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?

I'm building the schematic with Eagle now. Do I need any other components, suchs as caps, in order for the ATtiny to work properly?

Thanks for your help guys!

EDIT: Will the buttons work with the ATtiny? I wired them (Or "it" at this time) as instructed on this page.
« Last Edit: December 19, 2012, 09:52:20 am by iDroid » Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried something with using millis() to run a clock. That had a longterm drift (a minute or so every day). That was with an (older) Arduino with a crystals - the newers ones have something else that is not as regular.

Get an RTC chip, maybe on on a breakoutboard w/battery, and use it. (I dont know if you can get something that will interface easily with the ATTiny). By the way, I could set the 24 hour clock using just one push button (and some patientence)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I'll try to get one of those in my hands.

Well patience... doesn't quite belong in my vocabulary. Besides, it isn't very convenient if you have room for two buttons. I'll be setting the time in the code anyway before I upload it. I'm adding the button mainly for demonstration.
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need to (re)set the time sometime. Daylightsaving f.ex. Or a powerloss, battery change. The "patience" was that my little onebutton algorithm involved waiting for a few secs for it to advance to the next digit and entering 9 required - yes, nine pushes.
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 93
Posts: 3967
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?

Not at all. Search the forum, discussions on why this is not a problem constitute approximately 42% of the posts on the forum  smiley-wink
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need to (re)set the time sometime. Daylightsaving f.ex. Or a powerloss, battery change. The "patience" was that my little onebutton algorithm involved waiting for a few secs for it to advance to the next digit and entering 9 required - yes, nine pushes.

Oh, I thought you meant pushing the minute button 60 times to advance one hour smiley-grin
Well, that's convenient enough. May I ask how did you do it?

The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?

Not at all. Search the forum, discussions on why this is not a problem constitute approximately 42% of the posts on the forum  smiley-wink

Okay, thanks!

Logged

Pages: [1] 2   Go Up
Jump to: