NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Using source code

August 27, 2009
by Scott
Scott's Avatar

I must be missing a key piece of information. I am having no trouble progamming my MCU as long as there is a "make" file. I can't figure out how to come up with that file if I just have the source code. For instance the clock code is just a realtimeclock.c file. How do I make the "make" file so I can load it.

August 27, 2009
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Scott,

You need to provide a Makefile for some of these projects that are found on our website. The easiest way to get started is to make a directory for that project in your Code folder, and copy the Makefile from a different project (initialload's Makefile works). Then do a replace-all initialload with realtimeclock or whatever your C file is called. Admittedly our guide does not do a great job of explaining the Makefile, we are planning revisions to the guide that better explain it, or a tutorial coming up in the future.

Let me know if you have any more questions, I can provide more details as to the workings of the Makefile if you desire.

Humberto

August 27, 2009
by Scott
Scott's Avatar

Thanks. That was easy. I new what I was trying to accomplish, I just wasn't approaching it the right way. Thanks again.

Scott

August 28, 2009
by Nerdful_com
Nerdful_com's Avatar

What I do is: I have a temp directory with copies of the premade initialload c file and the makefile. When I am testing new code out, I just save source as initialload.c in this temp folder and then run the make file. If I find the code works and is what I want to work on, then I save the file as a new C file then go through with making a new makefile (I just take the one from initialload and replace all "initialload" with "myproject"). I find much of the source codes aren't what I was looking for, so making new makefiles everytime may be frustrating to some (me anyhow).

Nerdful.com

August 28, 2009
by mcai8sh4
mcai8sh4's Avatar

I may as well add my method for new projects :

I wrote a little bash script, like a windows batch file, called 'mkproj' (I'll get to the details of this in a second), I also have a makefile template which is just a copy of one of the Makefiles that Nerdkits supplied (poss the tempsensor one) but I've changed the word 'temsensor' with '###' throughout the file.

So all I have to do is run the bash script with the name I want (ie. mkprog test) and it automatially creates a dir called 'test', a file within the dir called test.c (and opens it ready for editing) and then copies the template makefile into the directory renameing the '###' with 'test' (using

sed ~/path/to/template_Makefile -es/###/$*/g > Makefile

). It's simple but works really well.

Whilst this is my method - I should add that learning about the makefile would certainly help in the longrun, but for us newcomers using a template file is the quick and easy method.

August 28, 2009
by Nerdful_com
Nerdful_com's Avatar

I still need to learn more about the makefile myself. Sometimes the amkefile needs to be changed (or it will not compile) when using your own/borrowed include files as an example (ones that are not included with WinAVR).

HERE is a link to Google/Yahoo AVR makefile search...

August 29, 2009
by Scott
Scott's Avatar

Thanks. I got my "make" file figured out and I have been programming the MCU without any problems. I would like to take the real time clock project a little further than the counter but I dont think I can write the code to get a full fuctioning clock. I would like to get a full fuctioning clock and compare its accuracy to other clocks with different frequency standards. I have a 10Mhz Temperature compensated crystal oscillator I would like to use instead of the crystal that comes with the kit. Any ideas or help?

August 29, 2009
by Farmerjoecoledge
Farmerjoecoledge's Avatar

Hey Scott don't be too suprized if you don't get an answer to your crystal q. mcai8sh4 and nerdful are using your q to face off and only back out when they find they don't know everything. Try not to worry too much about mcai8su4 technical stuff after a while some of it actually makes sense. As for your q sorry don't know for sure about the diffrence just keep reading and if you really need an answer ask the staff directly.

August 30, 2009
by mcai8sh4
mcai8sh4's Avatar

Hi Scott - I can't help with the different crystal (not a clue) - but for a clock example try looking at Waywards vicious alarm clock - I think he uses a seperate circuit to get the time more accuratly.

For a basic clock, I made a binary clock (easily adapted to show the time normally) - that seems pretty accurate - but I haven't ran it for 'days' so can't vouch for the gain/loss in a real life situation.

@Farmerjoecoledge - we're hardly'facing off' we've both found that the more variations of something you see, the easier it can be to understand. I can see where you could get the impression of some sort of 'competition', but there really isn't.

August 31, 2009
by mrobbins
(NerdKits Staff)

mrobbins's Avatar

Hi Scott,

If your 10MHz TCXO has a CMOS-level output (approximately 5V square wave), you can use the "External Clock" mode of the ATmega168 (see datasheet page 36). However, this would officially require putting changing the fuses on the chip, which requires an ISP programmer. But I am 95% sure that if you just connect your clock signal to the XTAL1 pin (MCU pin #9) and leave XTAL2 unconnected, it should work fine as well. I'm curious -- let me know.

Do note that changing the clock frequency changes the baud rate that the serial port runs at (currently set at CLK/128), which may complicate programming with the bootloader.

Hope that helps!

Mike

Post a Reply

Please log in to post a reply.

Did you know that NerdKits make a great parent/child activity? Learn more...