Page 4 of 7

Posted: Thu Nov 17, 2005 5:17 am
by PetPirate
Bred wrote:Those lights are bright!

Very cool thread; I'll be wiring up some LEDs and resistors this weekend.

Have you experimented with red LEDs at all?
Cool -- be sure to post pics!

I haven't tried red. I don't think they would be much good.

PufferMamma -- I hooked up these new, improved lights last night, and guess what? I saw some fluorescence! The closed zoanthids and the shrooms really stood out.

Posted: Thu Nov 17, 2005 5:19 am
by PetPirate
OK folks, I'm in two minds here. I need you to help me make a decision:

Do I:

1. Continue building the whole circuit -- add the remaining components, and then show the full code here

or do I

2. introduce programming now, and show just the code for getting the moonlights to light, then build the next step in, and show updated code?

It's YOUR CHOICE!!!!

Posted: Thu Nov 17, 2005 2:04 pm
by Jager
save time throw it all together. ill prolly send you the cash for the chip... to many things to do besides relearn how to blow up electronics.0-0) i do that enough with PC parts..... 1!) 3)

Posted: Thu Nov 17, 2005 6:00 pm
by midgetwaiter
This is cool Jhong, I've been messing around with exactly the same stuff lately. Great minds think alike.

Cool idea I've been thinking about coding up....

Build a timer into the controller to cycle the LED intensity in time with natural lunar cycles. I was just going to throw a pot on the circuit to I could play with the intensity manually but I'm just not organized enough to remember to do it.

I may just have to break out the ole simulator and see what I can come up with. Anyone else interested?

I vote for option 2 btw.

Posted: Thu Nov 17, 2005 6:25 pm
by Quaid
2 sounds good, but since I'm not actually participating physically, it doesn't matter either way!

Posted: Thu Nov 17, 2005 6:56 pm
by puffermama
c00l Jhong ... I knew it all along!

Posted: Thu Nov 17, 2005 7:44 pm
by YBeNormal
Being a somewhat patient person that likes a little suspense in life, I like option 2. Besides, I really enjoy understanding what I am doing and why rather than just how.

Posted: Sat Nov 19, 2005 12:19 pm
by PetPirate
And.... the results are in........

(drum roll.......)


A UNANIMOUS result.... you voted, by 3 to 0, for.... OPTION ONE!!!!

er, no... sorry... I mean

OPTION TWO!!!!

[cheer rings out]

Posted: Sat Nov 19, 2005 12:20 pm
by PetPirate
OK, so let's write a simple test program...


Fire up MikroBasic, close the example project it gives you, and start a new project.

It'll ask you to enter a bunch of options. Under "Device", select our baby: PIC 16F628A. Under "Clock", choose 20.0000MHz.

On the left, you'll see a list of "Device Flags". These are "Fuses" in the MCU that enable or disable certain features on the chip. If we don't select anything here, we'll have to select them when it comes time to program the chip. That becomes tiresome fast when you program a chip many times over for testing. If we set them here, the programmer should follow our settings, like a faithful dog. :D

Here are the settings:

Image

Suffice to say, check the "_OFF" options for everything, and choose the "HS" option to tell it we're using a High Speed crystal.

Now, some bright spark at MicroBasik obviously thinks it's a great idea to let you tick all the boxes... including _ON and _OFF fuses for the same function. If you think it's a good idea to select both _ON and _OFF for a function, then you win a very special Dunce Of The Year (tm) cap (limited edition). :lol:

OK, now we've set the options up, it's time to write a program.

First we need to understand a bit about the chip. 8O Here's a pic of it:

Image

See, the chip is divided up into two ports - PORTA and PORTB. Each port has eight pins. Like this:


These pins are controlled by "registers" inside the chip. A register is just a memory location that we can put a number in. The value of the number controls features on the chip.

The pins are called "tri-state". That is, they can be an input (read data in), or an output (send data out, or turn stuff off and on), and the output can either be ON or OFF.

Note that there are eight pins on each port. This is not some random number chosen at will because of the chip designer's love of the number eight.

No.

You see, the chip works in binary. Sounds complicated? falling asleep? No need to, Binary is simple. It means things are either ON or OFF. 1 or 0. No 2 or 3. Just 1 or 0. Without getting too complicated, for our chip, "1" is 5V, and "0" is 0V.

One binary number - 1 or 0, is called a BIT.

You know what a BYTE is, right? You probably talk about megabytes and gigabytes pretty often. Well, a byte is eight bits. A chip usually operates on one eight-bit register at a time.

So our pins are split into two bytes - PORTA and PORTB.

Here's a random byte for you:
11101010

(Some Super-Geeks can convert this into a decimal number in their head. I can't. I use the Windows Calculator. It's 234, if you're interested :roll: ).

This byte is eight bits long. Of course. All bytes are. The first number (1). is called BIT 7. The last number ( 0 ) is called BIT 0. (Computers always start counting at zero, just to annoy us)

OK, OK.. enough of all this nonsense..... I couldn't give a flying hoot how the darn chip works.. how do I program it? Some of us did say we wanted to build first, not do this programming rubbish.

It's OK. I understand. That's all the theory there is. It's explained. Done. 8)

See, The above is key. Remember we have eight pins on each port? We control whether they are inputs or outputs by dropping a byte into a register. The TRI-STATE registers. (known by the chip as TRISA and TRISB). We use a 1 to set it as an input, and a 0 to set it as an putput.

So, if we want PORTA.7 to be an input, and all the others to be an output, then we set:

Code: Select all

TRISA = %10000000
The "%" just tells MikroBasic that this is a binary number, and not a really big decimal number.

For our test program, we won't be reading any data in, so we can set all the ports to outputs. Like this:

Code: Select all

TRISA = %00000000
TRISB = %00000000
Tha'ts the most complicated thing in our program!!! And understanding it will give you enough insight into understanding the rest.

You can understand the rest by just looking at the comments in a code.

Comments are denoted with an apostrophe (').

For example

Code: Select all

a=1 ' This sets a equal to one
See?

OK, let's write our test program then. Our program will flash our moonlights on and off once every second, for EVER.

Here's the full code for this simple but sexy program.

Code: Select all

program Moonlights ' This is just the name of the program

Symbol Moon = PORTB.3  'This assigns a name to PORTB.3
                                      'Our moonlights are on here. So now, 
                                      'instead of having to remember which port pin
                                     ' they are on, I can just write "Moon".

main:                            ' The main program starts here
TRISA = %00000000      ' All pins on PORTA are outputs
TRISB = %00000000      ' All pins on PORTB are outputs

Here:
  Moon = 0                    ' Turn the moonlights off
  Delay_ms(500)            ' Pause for 500 milliseconds
  Moon = 1                    ' Turn the moonlights on
  Delay_ms(500)           ' Pause for 500 milliseconds
Goto Here                     ' Go back to the label marked "Here:"

end.                            ' This is the end of the program


Type this into MikroBasic, and then choose "Build". MB will compile and build our program and save the machine readable code in a .HEX file, which we can then download to our chip.

Find the .HEX file, and open it in the programmer. Check that the fuses are the same as we want them to be :

Image

Yep, the fuses are all as we set in MikroBasic... good.


Then program the thing. Here she is in the programmer, all ready to be delivered with her new brain:


Image


Done!


Slip the chip into the socket in your circuit (The right way round, unless you like the smell of burning toast -- pin one goes to the top left. )

Dadaaaaaaa! the moonlight flashes. Not the super brightness I promised..... but you must admit, flashing moonlihghts are cool enough! :twisted:

OK, so we can contain our excitement, it's not PWMing yet... but we've tested our circuit and proved that it works. The chip controls the moonlights. Time to sit back and give yourself a pat on the back. It's all downhill from here. Really, this time.

In future programming installments, I'm just going to post the code with comments for you to copy and paste into MikroBasic. :wink:... .

ANYWAY, ON TO SOUPING THIS BABY UP! WATCH THIS SPACE!!!!

Posted: Sat Nov 19, 2005 1:22 pm
by puffermama
OY! I wanted you to carry on the charted route (even though it all sounds like Latin to me) and to my reading it seems to me Jager's post is saying to carry on as before (unless I'm not reading him right) so by my calculation that would be 2:3, not 0:3 as you said and definitely not "...All 1 use .."!!

I guess the 3's have it, but I WON@T BE IGNIRED!!!!

Sorry, I'll calm down now, it's just that I'm dreaming of a future in salt ... with flourescence and luminescence and... well, everything!

Posted: Sat Nov 19, 2005 1:38 pm
by Jager
puffer mama these can be used on any tank.

if you think about it the only reason it is so salt specific is that saltwater animals and inverts are known(by the general population read Joe six-pack and his lfs) to need moon phases to spawn. I'm sure there are quite a few FW ones that do too.

Puffers love this regardless. they enjoy a good blue romp :P and when everything goes blue you would swear the disco era was back. mine under this lighting go exploring everywhere like its a new tank:P

Posted: Sat Nov 19, 2005 2:03 pm
by puffermama
Hey, that didn't used to be your location. Wait a minute .... that's MY reef!!!

:shock:

Posted: Sat Nov 19, 2005 10:34 pm
by PetPirate
puffermama wrote:OY! I wanted you to carry on the charted route (even though it all sounds like Latin to me) and to my reading it seems to me Jager's post is saying to carry on as before (unless I'm not reading him right) so by my calculation that would be 2:3, not 0:3 as you said and definitely not "...All 1 use .."!!

I guess the 3's have it, but I WON@T BE IGNIRED!!!!

Sorry, I'll calm down now, it's just that I'm dreaming of a future in salt ... with flourescence and luminescence and... well, everything!
Are you suggesting..... A MISCOUNT????. The CHEEK of it!! My brother Jheb PERSONALLY and INDEPENDENTLY oversaw the ballot counting! :lol:

Posted: Sat Nov 19, 2005 10:54 pm
by Fella
oh my god

Posted: Sat Nov 19, 2005 10:57 pm
by PetPirate
Fella wrote:oh my god
Is everything OK? :?