# Programming a homemade speed controller (compilers, assemblers and all that)



## xrotaryguy (Jul 26, 2007)

As many of you know, I am trying to build my own speed controller. Eventually I want to built a 3-phase AC controller for an AC induction motor, but for now I am trying to build a DC controller so that I can get my feet wet with something a little simpler.

Right now I have an AVRDragon with a Dragon Rider sitting on top of it. I also have a prototyping area put together with an IXYS driver, a 5k pot and a 12V light bulb so that I can get started testing hardware and code.

Here's the problem, I am new to programming microcontrollers. I have done some programming in Matlab and have created script files with Autocad, but that is not the same as writing C code, compiling it into machine language and then assembling that code / sending it all to the microcontroller, etc.

I have been tinkering with AVR Studio and some code that someone else wrote for a 36V speed controller (found on this site). Unfortunately, according to the help section in AVR Studio, the program does not contain a compiler. That seems weird to me, but then I am not much of a programmer, so maybe that is the norm.

I also downloaded WinAVR, but it looks even less user-friendly than AVR Studio. I don't really want to deal with that, but I will if I must.

What programs have you guys used to do this stuff?


----------



## etischer (Jun 16, 2008)

What are you trying to program? A pwm signal? Do you really need to have a complicated program running for this? How about a circuit that converts an analog signal to a pwm, and just have a program that controls the analog output. There are a few 12 volt plcs out there, plc code is tyipcally used for machine control. Allen bradley SLC500 has a plc power supply that runs on 10-30vdc, siemens also has a 12v plc. That's how I'd do it. Im also building a 3 phase motor controller myself. Im using a eurotherm drive as a base, it has a programming software package already designed for controlling a motor. 

here is the manual for my drive, it will be used as a firing circuit for my igbts. Start, stop, healthy logic is already done. Ramp shapes& rates are done. Has PID loops for doing cruise control. .. You can add, multiply, divide, do look up tables. My drive has 4 digital ins, 2 digital outs, two analog inputs, and one analog output. The more expensive ones have 3-4 of each analog and up to 12 digital i/o. You can specify max / min speed, torque... there are hundreds of parameters to play with, and that is a drive with out the "tech box". The tech box is the brains which allows you to do more advanced functions, such as speed program winders and diameter calculators used in industrial machinery. 


http://etischer.com/awdev/drive/eurotherm_manual/f202.pdf


----------



## xrotaryguy (Jul 26, 2007)

Looks like you're going to use a CNC machine controller. Excellent idea. That one looks like it will go up to 230V RMS. That's pretty decent for about $800. Very nice indeed. 

I am actually working toward a 460V RMS inverter, but that's somewhat beside the point. I just don't want to use hardware from a CNC machine for a variety of reasons. Plus, I really want to built the controller my self. I'm getting into the focus classes for my electrical engineering degree and this is experience that I need.

a plc would certainly be a neat way to go and I have looked at a couple of EVs with that use a plc for speed control, but I am simply looking to do more... eventually.

I have actually built a simpler speed controller using a pair of 555 timers. I just wanted to build that to get some circuit building and soldering experience. Now I'm moving on to the next step which is building a programmable version of the same thing. 

I'm using an Atmega8 because... well, they're really popular for use in robotics and homemade speed controllers. When I start messing with 3-phase hardware I will switch to a more purpose-specific Atmel microcontroller.

So... compiler recommendations?


----------



## etischer (Jun 16, 2008)

Acutally these are inverters that Im using, I picked a 2hp for $41 bucks, and a 3hp for $83. They are used for pumps, fans, winders, conveyors... Cheap way to go if I can actually make it work. 

Your project makes a perfect senior project for an EE degree! If I can help you at all let me know. For one of my EE classes we had to make our own motherboard, the second semester we had to write assmbly code and make it run on there. We used the motorola MC68000 family processor. For a compiler.. I don't remember what we used, I hated it though, thats all I remember =) Im sure I have a book in the attic somewhere. 

PLC programming is much more user friendly =)


----------



## judebert (Apr 16, 2008)

I don't do a lot of embedded programming -- mostly for PalmOS. But I do program a *lot*. And the free tool of choice for programmers everywhere is GCC. 

It's fast, efficient, and free. Because anyone can look at the source code, it has been adapted for many processors and embedded chips. In fact, according to the Atmel site, there's a GCC available for use with AVRStudio.

Atmel also has a page with other compilers that support AVR.

I believe that's what you're looking for? And if you need any help with the C programming, I'll be available to assist.


----------



## manic_monkey (Jun 24, 2008)

etischer said:


> Acutally these are inverters that Im using, I picked a 2hp for $41 bucks, and a 3hp for $83. They are used for pumps, fans, winders, conveyors... Cheap way to go if I can actually make it work.
> 
> Your project makes a perfect senior project for an EE degree! If I can help you at all let me know. For one of my EE classes we had to make our own motherboard, the second semester we had to write assmbly code and make it run on there. We used the motorola MC68000 family processor. For a compiler.. I don't remember what we used, I hated it though, thats all I remember =) Im sure I have a book in the attic somewhere.
> 
> PLC programming is much more user friendly =)


an mc68000?? you got spoiled! in my computing degree we had to write machine code for a z80, and then program it in using a hexadecimal touchpad


----------



## Rod Fitzsimmons Frey (Jun 12, 2008)

manic_monkey said:


> an mc68000?? you got spoiled! in my computing degree we had to write machine code for a z80, and then program it in using a hexadecimal touchpad


We had to use an abacus with magnets on each end, and program it using wool and an amber rod.


----------



## ga2500ev (Apr 20, 2008)

Take a read of this page here:

http://www.scriptforge.org/2008/05/avr-8bit-ides-and-freertos/

Maybe it'll give you some ideas.

Firmware programming is in my wheelhouse. I'm comfortable writing in assembly, C, BASIC, Python, and whatnot. In fact I've even written my own PIC compiler, though it's still incomplete.

The right direction is to decide what language and environment that you are comfortable operating in, then try to find the tools to match that.

I teach a programming languages class. At the end of the day, they are all pretty much the same once you reach the level of block structure. But C gets the most press only because it has such a huge following.

One language that's on my to do list that I believe may be worth learning is Forth. It does require a bit of a different mindset than other programming languages. But once you get it under your belt, it provides rich opportunities for quick self contained developement without needing a lot of infrastructure from the host. There's a Forth system for the ATMega here:

http://amforth.sourceforge.net/#

A nice gentle introduction can be found here:

http://astro.pas.rochester.edu/Forth/forth.html

There are a plethora of Forth systems that run on virtually every type of hardware. So you can download a Forth compiler for the PC, noodle around a bit, then start working on the Forth system directly on your target.

My interest in Forth was peaked by the idea of implementing a very tiny forth kernel on the target. This paper:

http://pygmy.utoh.org/3ins4th.html

Describes the process. Once you have this loaded, then you can start building your larger system on that foundation. I was intrigued by the fact that you could co-develop with real hardware by developing high level Forth tools on your PC and then transfer them down to your target once you've perfected them.

But there are only two rules in my mind that are truly important:]

1) Pick an environment that you feel comfortable operating in.

2) Be sure to utilize all the hardware resources the target hardware provides. If there's hardware PWM, then use it. If you need a timer, use a hardware timer. Same for serial interfaces, ADC, USB, and the like. The more on board hardware you use, the better off you will be.

Hope this helps. I'll be hanging around this thread to discuss any other issues.

ga2500ev


----------



## manic_monkey (Jun 24, 2008)

Rod Fitzsimmons Frey said:


> We had to use an abacus with magnets on each end, and program it using wool and an amber rod.


i heard a story once that there was a guy in my home town who back in the 80's used to program with a battery and some wire to make connections.

he also supposedly tried to build an 8bit processor using discrete components. now that wouldve been a sight!!


----------



## Qer (May 7, 2008)

I've programmed various AVR's in assembler for several years to keep the programs small and efficient but one day I realised I lived in the 21th century! Wha...? When did that happen? 

I'm currently working on a ventilation controlling program that eventually will handle the fans in the new dog house. Sounds easy, is tricky since I want to keep the heating cost to a minimum by only run the fans when needed. I will add moisture sensor and possibly a CO2-sensor just for kicks and also try to use outdoor temperature as much as possible to heat or cool the house. To make things even funnier, I will dig down a plastic tube between the dog house and the green house to use the spent air to heat the green house in the winter, but I will only pump enough air over to the green house, otherwise it might get too hot in there and the plants will die. It's a bit of a challenge and I like challenges. 

Anyway, I say go C++! There's an avr-gcc-c++ compiler that gives you C++-objects, however that's all you get. There's no STL or so, just a plain and very compact libc but just the ability to structure the code and end up with a main function that looks like:

#include <string.h>
#include <avr/io.h>
#include "uart.h"

int main( void )
{
uart tty0 (1000, 9600);

tty0.write_string ("Hello EV-forum!\n");
}

It's soooo much nicer than trying to keep track of assembler or even C! Small black boxes that can be arranged and rearranged at your whim. Sure, it gets bigger than assembler (but not much bigger than C), but there's AVR's with pretty huge flash memories so no worries.


----------



## Deekman (Jun 29, 2008)

When I was of the mind to fuel inject the spit, I was pretty active over at the megasquirt forum. I was even a moderator for a short time.

The developers over at MegaSquirt are embedded programming masters and they're familiar with PWM technology, using it in current limiting in fuel injectors and idle valves, etc... I can drop them a line over there and see if they would be interested in doing a DC motor controller.

To be honest, a DC motor controller would be easy peasy rice and cheesy compared to an EFI controller. (Mind, it does spark and a ton of other stuff too)

Bowling and Grippo developed the original DIY Fuel Injection controller... why not a DIY DC Motor controller?

-Deek


----------



## Doc (Jul 5, 2008)

xrotaryguy said:


> What programs have you guys used to do this stuff?


imo You should check out www.mcselec.com and the AVR compiler Bascom. I've been using that for 10 years doing both hobby and commercial projects. It's a AVR Basic compiler that is realy easy to use and with alot of built in functions that simplifies writing code and it's free to use for non commercial and up to 4k of code, and it supports Atmels programmers. 
It's my choice since I can write in both basic and assembly, and make my own libraries and the full version is only EUR79 

This is how simple you set up a timer for PWM with Bascom:
Config Timer2 = Pwm , Compare A Pwm = Clear Up , Prescale = 1 

and then you just change one 8-bit value to set the PWM duty cycle.

Theres also a brick of a PDF manual and an excelent user forum.

Huu, I sound like I'm selling Bascom, don't I... 

Good luck


----------



## hyper24 (Jun 13, 2008)

Avrstudio with the winavr add on seems to be the best choice, is simple to use. (can just open up, write code and hit program) but it has all the extra functions anyone would need. After searching for something to use I settled on this and it seems to be the best choice (for me anyways) but many people out there agree that avrstudio is the best... and its free! 

check out www.avrfreaks.net.

A $3 dollar atmega8 has

- 3 PWM channels 
- 6 ADC channels
- Watchdog timer
and many many more other features.

There easy to use, I love them.


----------



## xrotaryguy (Jul 26, 2007)

judebert said:


> It's fast, efficient, and free. Because anyone can look at the source code, it has been adapted for many processors and embedded chips. In fact, according to the Atmel site, there's a GCC available for use with AVRStudio. And if you need any help with the C programming, I'll be available to assist.


Ahah! Thanks for the heads up. I was wondering what those start-up options were every time I started Studio. 

GA2500EV,
Thanks for the advice and for offering your assistance. I just about have my heart set on using Studio to do the C programming and debugging and MAKE for the compiling. However, I contacted the professor that will be teaching my C++ class this semester, and he says that we will be using Microsoft Visual C++ Express, so I might look at that and see if I like it better. We'll see... I've already gotten quite a bit done (by my standards  ) with Studio, so I don't really want to switch right now.

This is where I am currently at:

I have C code written and I think I have a Makefile written. They can both be viewed here.


----------



## fugdabug (Jul 14, 2008)

Hello, 
If you are trying to compile a C program, there are some very nice compilers available (FREE!) by doing a search on the CNet downloads database I use a compiler called ICC. 
However this matter of writing the program in C, learning C, getting a compiler should only be undertaken if you are planning on upgrading the software (firmware yourself) or are doing experimental work. You can render your controller to the status of an expensive doorstop. 
I think you should ask yourself; why do I need to program (re-program) the controller?
Programming in C in not an exact science... there are a number of variations of C out there and though it is used in fundemental Linux Programming and some scientific applications... weigh the time of learning the nuances of C and finding ready-made programs for the controller.
Just some thoughts.
Respectfully yours,
fugdabug


----------



## Qer (May 7, 2008)

xrotaryguy said:


> However, I contacted the professor that will be teaching my C++ class this semester, and he says that we will be using Microsoft Visual C++ Express, so I might look at that and see if I like it better.http://www.box.net/shared/1613zjtgco


Can Visual C++ Express generate binary code for an AVR? I would guess it can't, but I don't use WIndows or Visual Studio so I don't know for sure, however it would surprise me if it can.

Yep. All (or at least most, some are compatible) CPU's use different binary formats if you didn't know. To make it even more hopeless, all OS and environments tend to use their own as well, so it's not enough to have a C or C++-compiler, you got to have a compatible one...


----------



## xrotaryguy (Jul 26, 2007)

Thanks again for the comments guys. I was starting to come to the same conclusion about Visual C++ as I can find very little information about using it with an Atmel microcontroller. Hmm... I guess I will be learning how to deal with two different debuggers / compilers for the next few months. Fun


----------



## Qer (May 7, 2008)

It's not that hard, really. C++ is C++ no matter what, so all you need is some other tools. Since you're a Windows guy (right?) I guess that WinAVR is the way to go for you.

http://winavr.sourceforge.net/

Start there and yell if you have problems. Considering I prefer to use the gnu tools (I'm a Linux guy, you'd rather find me herding cattle than program in Windows ) I might, or might not, be able to answer.


----------



## xrotaryguy (Jul 26, 2007)

I wish I was familiar with Linux  Oh well, I'm just a knuckle dragging windows operator.


----------



## Qer (May 7, 2008)

xrotaryguy said:


> I wish I was familiar with Linux


At the risk of going totally OT and get banned from the forum for life, I still have to say it's not as hard as you might think. Shifting from Windows to Linux (at least one of the bigger, friendlier distributions) isn't that much harder than when Redmond releases a new version of Windows and NOTHING behaves the same anymore (Vista springs to mind...). It's harder, yes, but not even close to impossible.

I shifted from Windows to Linux back in -96 and the step was very much equal to when I shifted from MacOS to Windows. It's a different OS, your favorite programs don't work anymore and there's a first step that will be hard, occasionally very frustrating but it's not the end of the world and you'll get over it. 

You could always dip your toes in the water by either trying out Linux on an old computer or try a Live-CD. A live-CD is a Linux that boots entirely from CD and doesn't use the hard disk for anything. It's a great way to try out Linux (it's a fully graphical Linux environment, although you can't save anything since it doesn't use the hard disk), repair a broken installation or even, in most cases, install Linux on the hard disk while you keep surfing as normal.

Since Linux is an community driven development there's multiple solutions with their cons and pros. Here's a short, although biased, introduction of the distributions I have experience from:



PCLinuxOS (http://www.pclinuxos.com/) is a pretty new distribution which shows promise but in some ways it doesn't feels quite ready yet. It only comes in 32 bit flavor aimed for desk computers and laptops. What impressed me is that it's VERY simple to install and that it managed to set up wireless network cards with a minimum of effort. Very nice indeed. GUI looks a bit clumsy (or at least looked when I tried it last time) but it works nice and aims at total newbies. You download one CD-image which is both a live-CD and install media and it just works, which is pretty nifty.
Ubuntu (http://www.ubuntu.com/) gets a lot of media attention and is recommended by a lot of people as currently the best distribution. I don't agree, but that's my opinion. One of the things that doesn't work as nice as in PCLinuxOS is that the live-CD/installer misses to set up, for example, keyboard layout and expects you to be ok with US map. Pretty annoying if you happen to live where an alternative layout is the norm.
Fedora Core (http://fedoraproject.org/) is produced by RedHat, which is a very old and experienced distributor by now. They know their stuff and that's my favorite flavor. Fedora Core is their cuttin' edge experimental platform so especially new releases can be very buggy. Right now Fedora Core 9 is their latest release which contains a lot of improvements for laptops (and new, interesting, bugs) but if you're using a stationary I'd recommend going for Fedora Core 8 instead (it's pretty stable by now). Fedora comes as live-CD OR install-CD, not combined. Fedora also suffers from being based in USA which means that they don't distribute anything that can get you sued (like mp3-decoders), but there's a community driven project called Livna that provides those instead so no worries. Might be a bit less newbie friendly, but, hey, I'm no newbie anymore... 
Confused yet? 

As I said, there's a first step that can be hard, but it's not impossible and there's LOADS of information and forums on the net that can help you if you run into problems. If I can I'll answer any questions as well, to start with here's a mock-up FAQ with stuff that people usually ask:

Q: Do I need to reformat my hard disk to be able to install?
A: Strictly speaking I think it would be possible to run Linux on a NTFS-filesystem (ie, that Windows uses), but I would recommend against it. So yes, you'll need to reformat your hard disk. And while speaking file systems, there are several out there. Go ext3, it's perhaps not the best when it comes to performance but it's good enough for the average user, ancient and rock solid (at least as rock solid as they come).

Q: I can't run Microsoft Office, MSIE or Outlook!
A: Correct. But you can run OpenOffice.org (yes, it's called that) instead and it's very (although not 100%) compatible. For web and mail I recommend Firefox and Thunderbird. They're all open source and free (of course).

Q: What virus protection should I use?
A: Why would you? Linux (and Mac OSX) is UNIX-based, it doesn't have the weak security that makes viruses a huge problem like in the Windows world.

Q: Can I use my printer/graphic card/scanner as usual?
A: Depends. Some hardware manufacturers actually help the community with specifications or drivers, that hardware usually works very well. Other hardware is reverse engineered which means that they might work as usually or just partly depending on how far the work has come. Then there's hardware that will probably never work and where the manufacturer won't help a bit with the process, unfortunately. Short note on troublesome hardware:


Network: Most network cards work. Some wireless cards can be problematic, I believe Netgear are among them.
Graphic cards: ATI and nVidia don't release specifications but they provide drivers. nVidias drivers seems to work well but I've had problems with ATI's drivers. ATI is, on the other hand, bought by AMD now and they've said that they will help the community with open source drivers. If they do, odds are that ATI will soon have a rock solid support in Linux. Intel are already providing open source drivers for their graphic cards as far as I know.
Printers: Usually works well. HP's ink jet drivers for example usually works better in Linux than Windows. 
Scanners: Russian roulette. There's a list over supported devices here: http://www.sane-project.org/sane-supported-devices.html
Any questions...?


----------



## Bugzuki (Jan 15, 2008)

To see a little commercial robot motor driver you should look at the Pololu Orangutan X2. I has two Atmel chips and two low power DC motor drivers (14amp continuous - 30amp peak)

The drivers can drive 1 motor or 2 - forward and reverse.

http://www.pololu.com/catalog/product/738

They suggest to use the AVR Studio with WinAVR for the C compiling. They provide the schematics and some test and demo code. I have one and have played with it a little. WinAVR is not that hard once you figure it out. 

It plugs into the USB port and is programmed directly.

They give a lot of information on their site.


----------



## Bugzuki (Jan 15, 2008)

xrotaryguy said:


> I have C code written and I think I have a Makefile written. They can both be viewed here.


In your program it looks like you have some divide functions. I would take a look at how many clock cycles it takes to run the divide and see if you can spare them. Divide is usually processor intensive and on a small processor it can eat up a bunch of time. 

Otherwise looks like a good start.
Keep up the work.
Paul


----------



## skimask (Feb 18, 2008)

If I can butt in...'cause I haven't read the whole thread and I don't really know where the O/P is heading as far as building a controller...
http://www.picbasic.co.uk/forum/showthread.php?t=9221
I've been using PICs (www.microchip), PicBasicPro (www.melabs.com), and a PICKIT2 (www.microchip.com) for some fairly complicated projects...not this one linked in particular, but quite a few projects that might incorporate the same principles, ranging from OBD2 scanner, MP3 player, a 52 channel medium freq PWM controller for 12v lighting, a 127 channel audio spectrum analyzer, and a half-a-thousand other little doo-dad's...blah blah blah. And all using PicBasicPro. Yes, BASIC...like as in Beginner's All-Purpose Symbolic Instruction Code.
In short, if I was going to start to design and build a homemade speed controller tomorrow, this would be my list of pieces/parts to get:
PIC18F4685 @ 40Mhz (~$10USD) - main controller
PicBasicPro (www.melabs.com, $250USD) - BASIC compiler
MPLAB (www.microchip.com, free) - assembler
PICKIT2 (www.microchip.com, ~$50) - PIC programmer
PCBs, IGBTs, isolation devices, LCD, small keypad, the assorted 'glue hardware' that goes along with a project like this.
But that's just me...


----------



## ga2500ev (Apr 20, 2008)

skimask said:


> If I can butt in...'cause I haven't read the whole thread and I don't really know where the O/P is heading as far as building a controller...
> http://www.picbasic.co.uk/forum/showthread.php?t=9221
> I've been using PICs (www.microchip), PicBasicPro (www.melabs.com), and a PICKIT2 (www.microchip.com) for some fairly complicated projects...not this one linked in particular, but quite a few projects that might incorporate the same principles, ranging from OBD2 scanner, MP3 player, a 52 channel medium freq PWM controller for 12v lighting, a 127 channel audio spectrum analyzer, and a half-a-thousand other little doo-dad's...blah blah blah. And all using PicBasicPro. Yes, BASIC...like as in Beginner's All-Purpose Symbolic Instruction Code.
> In short, if I was going to start to design and build a homemade speed controller tomorrow, this would be my list of pieces/parts to get:
> ...


I'm a PIC guy from way back so I'll throw in some input too.

The absolute best resource for PIC stuff out there is the PICList at http://www.piclist.com It has tons of PIC code and other electronic resources. In addition it carries archives from the longstanding PIC mailing list, which is over 2000 members strong.

While PICBasic may be worthwhile if you're going to leverage it over dozens of projects, $250 is really steep if you are targeting a one off project. Recently HiTech software released a Lite version of their C compiler for the 12F/16F midrange family for free:

http://microchip.htsoft.com/products/compilers/PICClite.php

No code limits, no time limits, no nagging. The only thing disabled is their code optimizer. And as an added bonus for me as a Linux guy, they offer a Linux version.

The language that has really caught my eye recently is Forth. It's structured to let programmers build code in the conversational format that they feel comfortable by embedding code into easy to remember words. For example a perfectly valid Forth statement would be something like:

*power-led turn-on*

Now Forth does have its quirks, I'll be the first to admit that. However, I truly believe that even for novice programmers, that its ability to build efficient applications from the bottom is worth knowing.

There is a decent free Forth compiler for the PIC 16F series of chips here:

http://www.rfc1149.net/devel/picforth

Personally I'm determined to build my own tethered Forth development environment, where I can noodle with stuff in Forth on my Linux box, then transfer what works to the PIC board.

Also for PICs don't discount writing in assembly. With a limited number of instructions and tons and tons of code examples out there, complete systems can be written in assembly. But read the PICForth FAQ as to why it may not be the best choice.

The one last piece of advice I have is that no matter what language you choose to develop for PIC in, take the time to at least learn how to read PIC assembly. It's the _linqua franca_ of PIC development. Everyone speaks it so it's how ideas get transmitted. It's helpful to know even if you don't write in it.

Hope this helps,

ga2500ev


----------



## xrotaryguy (Jul 26, 2007)

Thanks for the comments guys. I haven't gone through this thread and clicked on all the links yet, but I promise I will. I really appreciate all the advice.

I decided early on not to go with PICs because their 3-phase motor controller development software and hardware were expensive. Atmel has a development board for about $300 and a free design suite. I plan on using their AT90PWM3B. They even include sample code for running the controller. From the PIC community you're describing, it sounds like I could put those things together on the cheap too, but I stumbled across Atmel's products first.

Anyway, I finally figured out how to use a makefile and compile all the c code into a hex file. I am now hunting about for info on how to use avr dude to burn the hex file onto my atmega8. 

I was unable to use programmers notepad to write to the chip. I read an instructable that said:

Windows:
1) Open up LED_Demo.c with Programmer's Notepad. 
2) Cross your fingers.
3) Select "Tools...Make Program"

This didn't work for me. I don't know if its because I'm using a Vista machine or what, but it didn't work. I finally went to the c prompt and typed:

1.) *avr-gcc -g -Os -mmcu=atmega8 -c speedy.c*
2.) *avr-gcc -g -mmcu=atmega8 -o speedy.elf speedy.o*
3.) *avr-objcopy -j .text -j .data -O ihex speedy.elf speedy.hex
(Thank you Peter)

*Ok, off to figure out how to use AVR DUDE.


----------



## Qer (May 7, 2008)

xrotaryguy said:


> 1.) *avr-gcc -g -Os -mmcu=atmega8 -c speedy.c*
> 2.) *avr-gcc -g -mmcu=atmega8 -o speedy.elf speedy.o*
> 3.) *avr-objcopy -j .text -j .data -O ihex speedy.elf speedy.hex*


You should learn to use make, then you don't have to type all that manually. Create a file you call "Makefile" in the same dir and write this in it:



> CFLAGS=-Os -mmcu=atmega8
> 
> speedy.exe : speedy.c
> 
> ...


Ok, some explanations of the steps might be needed I think. 



> CFLAGS=-Os -mmcu=atmega8


This tells make exactly what flags all the C-programs should be compiled with. I've skipped the -g flag since it's only used to create binaries with debug information in it. You don't need that unless you're going to use a debugger. I've also skipped the -c flag since you only have one binary. The -c flag tells gcc not to link the compiled object file into a binary, but since you only have one c-file gcc can as well compile and link in one step. I'll gladly explain how you link together several files later on when you need that, promise.



> speedy.exe : speedy.c


This line isn't really necessary, but it will come in handy later on when you want to link together several files.You don't have to tell make more than this to compile the binary since make has default rules for that and those rules use the variable CFLAGS for the options you want to use. Small warning here, in Linux I'd only write speedy rather than speedy.exe since binaries don't have to have extensions like in Windows so I'm a little unsure about the extension. I'm almost sure it's supposed to be .exe, but I'm not 100% sure.



> speedy.hex : speedy.exe
> _<tab>_ avr-objcopy -O ihex $< [email protected]


This tells make how to create a hex-file from the compiled binary. The _<tab>_ is a tab character! Very important. It's part of the make syntax and it has to be a tab, not just spaces. I know, picky and a bit of a pain in the lower region.



> .PHONY : program


This tells make that the rule "program" is phony, ie it doesn't create any resulting file called program. This is good for creating rules that do something else, like program an AVR-chip. If we don't tell make it's a phony rule, make can get confused.



> program : speedy.hex
> _<tab>_ avrdude -c bsd -p m8 -U flash:w:speedy.hex


This will program your AVR. The -c flag tells what kind of programmer you have, bsd is a home made programmer that is made out of an old parallel cable. It bit-bangs the data on the parallel port without any external electronics than the cable, which is about as cheap as it gets (that's what I use btw). If you have some other programming gizmo, you have to give the right option.

Since I haven't used the -g flag (ie to create a debug binary) I don't bother with the -j flags. Default is that avrdude writes down everything, but since you've limited it to text and data the debug info (that you compiled with) is stripped off the resulting binary. It's kinda unnecessary to compile with stuff you throw away again...

So, anyway, now you have your makefile. Just go to the directory and type *make* to compile the program and *make program* to program it to the AVR. You don't have to type *make* before you type *make program*, if you don't make will compile the program (if needed) before it's written to the AVR. However, it's nice to be able to only compile without writing it to the AVR sometimes. At least I think so, but it's just a matter of taste I guess. 

Oh, and while I'm trying to get you over to the dark side, you should consider using emacs as your editor. It's a bit tricky to learn, but once you've gotten used to it, odds are you'll be highly addicted. It's VERY powerful. My opinion is that it's very user friendly, however it's not very newbie friendly. 

Links:

It seems that the people behind GNU make recommends djgpp for pre-compiled Windows versions. They only speak about Windows up to XP in their FAQ, but I guess it should work with Vista as well. I can't verify since the only Windows machine I have is a gaming machine with a overfilled hard disk, I have no room for even extracting the files...

ftp://ftp.delorie.com/pub/djgpp/current/v2/readme.1st Read this! It explains a lot.

As far as I've understood you need to download these zips:

ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/mak3791b.zip for make
ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/em2005b.zip for emacs

If they don't work (I hope they do) google can probably find other sites with pre-compiled versions of the programs. From when I still ran Windows I know that there's almost always someone that has pre-packed the programs you might want, it's just a question of finding it...

Other good stuff:

http://www.gnu.org/software/make/ Home page for GNU make. Here you can find a manual and other information that can be useful.
http://www.gnu.org/software/emacs/ Ditto emacs.

Welcome to the dark side! We have cookies...


----------



## xrotaryguy (Jul 26, 2007)

Qer said:


> I've skipped the -g flag since it's only used to create binaries with debug information in it. You don't need that unless you're going to use a debugger.


 So I might use this if I were planning on running JTAG or something?




Qer said:


> I'll gladly explain how you link together several files later on when you need that, promise.


 Sweet, I'll need that when I start working with code for an AC controller.


The only text in my makefile will be:


> CFLAGS=-Os -mmcu=atmega8
> 
> speedy.exe : speedy.c
> 
> ...


 ??????


Wow, the makefile that I _thought _I was using is about 100 lines long, not a little 6 line jobby. What am I messing here? It's actually the sample makefile written my Eric B. Weddington.


Also, I'm using a 64 bit Vista machine. I suspect that may have something to do with my inability to simply type make or make file. I do have an old XP machine. Maybe I should just use that and see what happens.


----------



## Qer (May 7, 2008)

xrotaryguy said:


> So I might use this if I were planning on running JTAG or something?


Possibly. I don't have a JTAG-thingie so I can't tell, but it makes sense at least. I personally use the UART in the AVR that prints debug stuff to my serial port on the PC and I have a borrowed logic analyzer to make sure my program's shaking the right pins. So far, so good. 



xrotaryguy said:


> Sweet, I'll need that when I start working with code for an AC controller.


I'll write a note another day when it's not midnight and the missus is hinting that she wants to sleep...



xrotaryguy said:


> Wow, the makefile that I _thought _I was using is about 100 lines long, not a little 6 line jobby. What am I messing here? It's actually the sample makefile written my Eric B. Weddington.


Beats me. I've never understood the point with supersized Makefiles with extra everything. I prefer to keep them short and easy to read and modify. My makefile has a few more lines, but that's because I compile a few more files (4 or 5 or so). Unless it's the Linux kernel or something similair sized you compile there's no point in novel sized Makefiles.


----------



## 1clue (Jul 21, 2008)

Several comments here:

First, the off-topic comments regarding Linux:
If you only have one PC and you want to play without hurting something, then download VMware Server or something similar. It's free to use (not open source) and it emulates an Intel-based computer. Install your favorite flavor of whatever OS on there, and play away. We use it for testing. Keep in mind you are legally required to own the license for each image you have on there, meaning if it's a Windows virtual box then you need a license for each virtual image which has Windows on it. Installing Linux is not a problem since it's free.

_Edit: Linux works best on recent but not bleeding edge hardware. The installers assume you're using decent or common, current hardware. Anything super high performance (RAID, SANs, etc) or antique will not be in the main selection list.

_ I don't like Redhat-based distros. I started there, but it's the one-size-fits-none distribution and lots of "us" call it Microsoft Linux. I also don't care for Ubuntu for my personal use because I don't like Debian, but I've seen a lot of folks who were afraid of Linux install Ubuntu on real hardware in 5 or 6 minutes and have a system they knew how to use, so it might be your best way to cut your teeth. I use Gentoo (Do Not Start Here!) mostly, and a few other things just to see what they're about.

It seems that all the distributions which have a commercial version push for you to get the commercial version, sort of like when you watch basic cable. The more old-school distributions have forums which are more friendly to programmers and programmer wannabe's.



Now, back on topic: Have you searched for Open Source motor controller software? It seems that this would be an ideal thing to start an OS project for, and be modular enough to work with a wide range of hardware.

It would be interesting to participate in that sort of thing. I anticipate making my own controller and software when the time comes, so it wouldn't hurt to get my feet wet early.


----------



## xrotaryguy (Jul 26, 2007)

Cool, thanks for the added info and preferences on Linux. I have been considering using Linux on my desktop. Actually, I would like to use my Desktop as a server and backup the house's two laptops to it. The desktop is about 5 years old. I recently got a killer deal on a 750 gig hard drive and I plan on installing it soon. 

I am torn between using Linux for this application and using Windows though - the reasons are as follows. First, I am very familiar with Windows and the time required to learn a new OS is not attractive. Second, the desktop is the only computer that works all the time. By that I mean, it is the only computer that runs practically everyone's software. For example, I am taking an online class at one of the local community colleges right now. Their software is based on an older version of flash media. It will not work on Firefox. It only works on IE7. It will also not work on my Vista machine. 

The Vista machine is sweet as heck because it is rocket ship fast and has tons of neat-o features, but the fact remains that it will not run certain types of software. I'm sure this will change within the next year or two. By then this machine will be obsolete though right  Until the Vista machine will do everything that the desktop will do, I think I am stuck with Windows on all the computers in the house. Bootlegged Windows Home Server here I come.

OK, back to the subject at hand. Yes, open source software does exist for this application. You can view the source that this person used: zeva.com I do not plan on optimizing his software for an EV though. I am only working with a simple design and with simpler software so that I can get the hang of programming and building hardware. 

I am ultimately building an AC induction motor controller - that's the plan anyway. Atmel actually supplies software for this application: Atmel's software. Scroll to the bottom of the page to view the applicable information. If you're interested in an open source AC drive, then I certainly welcome the help. AC systems can be cheaper than DC systems due to the huge abundance of industrial AC induction motors. Not only that, but a homemade AC system has the potential to be considerably more efficient than a DC system, so it's a win win situation. The trick is building the motor controller - and oh what a trick it is *sigh*.


----------



## Qer (May 7, 2008)

More about make:

I think I forgot to mention one thing. You have to have a line like

CC=avr-gcc

high up in your makefile, otherwise make will try to compile the code with your Intel-compiler, which of course won't work. Sorry about that. This is how my makefile looks btw:



> CXX=avr-g++
> CXXFLAGS=-mmcu=atmega48 -Os -Wall
> 
> .PHONY : clean program
> ...


OBJ is a variable where I just add all object files that should be linked with my test program and the clean rule just cleans out everything that isn't source files so that you can do a clean compile if you want to see that everything still works as intended.

I've never explained the function of [email protected] and $< btw. [email protected] substituted with the target (in my makefile that is test.hex) and $< means the first requirement (in this case it's test). If I have a rule that looks like this instead:

program : object1.o object2.o object3.o

$< will expand to object1.o. If I want all of the objects I can use $^ instead which will include all three of them.

Make doesn't have a syntax that's easy to understand (I think that's an understatement, actually), but it's a very powerful tool and learning make will save you lots of time in the future. Especially when the project grows...

Regarding Windows-Linux I can understand that you need a computer that keeps working with the stuff you do, but I would still like to push a little for using Linux if you're planning a server. Computers are cheap and my bet is that you can get an older one cheap or even for free if you just ask around a little. My server is an OLD AMD 900 MHz with 8 disks (total disk space is close to 2.5 TB) and it's running flawlessly as my file and print server, firewall etc etc etc. Rock stable, always reliable and has never lost a file for me. My Windows machine (gaming thingie) topples over both now and then as a comparison...

In my experience it's worth going for Linux since it's way more stable with less problems with viruses etc (like next to none). In that case I'd like to point at CentOS as an alternative since it's a strict server flavor of Linux with a very conservative software policy (it's usually using older, more properly tried out, versions of the different software packages).

Alternatively maybe a network harddisk could do the job instead? No matter what, I'd never trust Windows with such an important task as storing my important files. It's too prone to do nasty things for my taste...


----------



## Madmac (Mar 14, 2008)

xrotaryguy

Still designing the hardware for a DsPic based AC controller ( with charger using most of the same parts) and having spent a little time trying to get to grips with the maths. From my current understanding if you want to control torque with the space vector algorithm you need to either directly measure current in the motor windings or infer it.

Having just looked at the Atmel description (not read the source) it seems to work only in a velocity mode, with no current feedback. Specify a target rotational speed and it will close in on it.

Not being a motor person, most information points at torque control being preferred for control in an EV. This raises two points, firstly is the 8 bit AVR powerful enough to support a more complex space vector system, and the second does it matter that much if control is just RPM (or have I misread the application note).

Is there any advantage to using the Atmel part if the algorithm has to be rewritten from scratch?

Madmac


----------



## 1clue (Jul 21, 2008)

Hi again.

Thanks for the link to the other software and hardware. There seems to be some confusion about open-source and what exactly it means. The software you linked to might be public domain, or maybe it has some licensing constraints based on the libraries used, but it does not seem to be open source.

Regarding Linux: When you get your 750g drive up, download VMware Server and set up a linux image on it. Find out if there is any one computer whose entire functionality can be replaced by that Linux image. If so, then you can scrape off that replaceable computer and install Linux on it. VMware makes experimenting with a new OS completely safe and painless, at least when it comes to reverting to your previous OS or interacting with it while you play.

I'm a dyed-in-the-wool Linux guy. I've been using it exclusively for almost as long as it's been viable to do so. Linux is very much like these electric cars we build, so I have no doubt your temperament is right for it. However, a lot of us overlook the difficulties because we're enamored by the things we can make it do. You need to make your own choices there. I find it extremely stable, very logical and infinitely configurable. Others find it unstable and unusable.

First thing though, if your computer didn't come with a complete restore disk, then make one. If you get tired of Linux you can always restore it as-from-the-factory if you have that CD or DVD. Otherwise you've lost a license and it gets painful to get it back, since you have to contact the vendor and go through hoops to get a copy of the image.

Thanks.


----------



## xrotaryguy (Jul 26, 2007)

Madmac, I think that the AVR software expects a signal from a pair of hall effect sensors and a reluctor. This enables the micro to figure out the motor's velocity (both speed and direction). The micro selects a field rotation velocity (which will be slightly faster than the rotor velocity) based on the speed of the rotor and the input from the accelerator pedal or 5k pot.

The advantage that I see with the Atmel stuff is that it is super cheap. For example, the Circuit Cellar design required some very expensive software (or was it the hardware that was expensive...) to actually burn the chip. Or maybe the issue was the cost of development hardware / software. It' been a while since I looked.

The point is that the AVR stuff is comparatively cheap and it's largely off the shelf (which was good for me because I was starting from ground zero when it came to embedded programming and hardware construction)

Atmel's Motor Control Center software is free, the AT90PWM3B chip is cheap (but aren't they all), they sell development hardware at a reasonable price, their software is free... yatta yatta yatta. 

Perhaps the same is true for the PIC stuff and I stumbled across the Atmel components first. Either way, I'm sticking with what I've got for now.

I tried to use that makefile on my Vista machine without success. When I type "make" it says. "no target specified no makefile found."

when I type "make all" it says, "no rule to make target 'all'"

when I type "make program" it says, "no rule to make target 'program'"

I think that this is just a 32 bit xp program trying to run on a 64 bit vista machine. Lame

I also tried to get my AVR Dragon working on my XP machine and the driver refuses to install. Is this why programmers don't like Windows?

Or do you guys not like Windows because my xp machine also refuses to install Studio? 

That settles it. I am installing Linux on SOMETHING asap!

I will continue attempting to burn a chip after that


----------



## Madmac (Mar 14, 2008)

Had a look at the schematics last night and the development board does have the current hooked up. There are sense resistors in all 3 legs of the bridge return lines. They are then buffered by opamps to scale for the AtoD inputs. Should be easy to modify for hall devices in a higher power version, although you might as well only use 2 (all three currents sum to zero).

The Pic motor development is two boards, one for control and the other for the type of motor to drive, this does work out more expensive if you buy them. The compiler used in the circuit cellar article is a commercial product and quite expensive, there are other lower cost as well as free options. The component costs for either manufacturer are about the same (Pic may be cheaper as it is easy to get samples and more MIPs). It is worth noting that all manufacturers give away basic source code for this application, TI, Analog Devices, STM, Luminary as well as Microchip and Atmel.

My view is there is little point in buying the development hardware for several reasons...the boards lack interfaces and features for safety, the product is not designed for use in a high dv/dt application ..... is unlikely to be stable (having the micro crash while driving and coming to a fast halt, if the stator coils remain powered the motor acts as a very good brake, part of the safety changes)...... tacking bits on to modify the existing design will be prone to vibration in an auto environment.

Spending the money on laying out a PCB to do the job ( as well as acting as a charger) means two versions for the same money, one to test the design and a second final one to correct errors and include modifications. Providing the design keeps the core features of a development board then the software will run on it. Then one can start on rewriting for an EV version.

Look forward to following your progress. The more people having a go the more likely it is that we can solve any issues that arise.

Madmac


----------



## xrotaryguy (Jul 26, 2007)

Very good Madmac. I agree about the development board. I liked that it was cheap and I thought I'd bring it up. However, I wasn't really sure what I would ever do with it haha.

Anyway, I made a couple of changes to the makefile. I had to change the programmer to AVR Dragon -p dragon_isp. Also, I think that I need to identify the correct USB port so that the computer doesn't default to the parallel port, so now the last line reads, avrdude -c dragon_isp -p m8 -P usb:0005 -U flash:w:speedy.hex

The whole makefile looks like:



> CC=avr-gcc
> 
> CFLAGS=-Os -mmcu=atmega8
> 
> ...


And it still doesn't work 

I cd into the directory, type make or make all or make program, and all I get is:


> No targets specified and no makefiles found


or 



> No rule to make target 'all'


or



> No rule to make target 'program'


----------



## Qer (May 7, 2008)

Those error messages means it doesn't find the makefile. Have you cd'ed to the directory that contains the makefile you want to run?

You can't type make all without having an all-rule btw. However make or make program should work.


----------



## 1clue (Jul 21, 2008)

You guys are having a problem using make, not a problem with Windows.

Change to the directory containing your source files.

If you have a file named *speedy.c* then in order to get a linkable module you type _make speedy.o_ and if you want to make an executable, then on Linux it would be _make speedy_, so I presume on Windows it would be _make speedy.exe_

Make (at least gnu make) understands how to do certain things by its default configuration. For example, it knows that if it wants a .o file and it has a .c file, then it uses the _cc_ command and is either aware of the parameters or can be configured with the parameters.

A _Makefile_ is a text file (for example the one you're describing) which contains instructions for the _make_ command. The format of that file is critical, including whether you use a tab or a space, and empty lines are also important depending on their placement.

You generally only need a Makefile if you have a complex sequence to build a running app. Compiling one file into an executable is not such a case, you would just say *make speedy.exe* and that's it.


----------



## 1clue (Jul 21, 2008)

Here's the manual for the gnu version of *make*.

http://www.gnu.org/software/make/manual/make.html


----------



## Qer (May 7, 2008)

1clue, read the whole thread, not just the last page. The reason make was introduced is because he's doing three steps for compiling and programming the result into a flash and in the future the project will grow.


----------



## 1clue (Jul 21, 2008)

Qer,

I understand that the command to create this file is fairly complex. I wasn't trying to deny that a makefile is helpful, I was only trying to say that the OS knows where the _make_ command is, but either can't find the makefile or can't read its format.

I've been following this thread for quite some time now, almost since I first joined the forum. (which really isn't all that long.)


I suspect that the problem is the lack of proper formatting on the makefile.


----------



## xrotaryguy (Jul 26, 2007)

Thanks for all the advice 1clue and Qer. I decided to do a little dinking around with Studio last night. As you guys are probably aware, Studio has buttons to display a connect dialog, connect to the programmer, write flash memory, write EEPROM memory and even an auto program button. So I gave those a shot. 

I seem to recall trying to use those buttons a while back before I really had a makefile sorted out, but I don't recall exactly what the results were. Obviously I didn't get the blinking light that I wanted, but I don't recall what the error messages were.


I clicked on the connect to the programmer button and selected the Dragon and Atmega8 chip and the programmer's red light turned off leaving only the green light on. 
I clicked on the write flash memory button, selected the hex file from the correct directory and that seemed to work (the green light on the programmer flickered as though data was transmitted). 
I clicked on the write EEPROM memory button and went to the same directory, but the only file visible was the same hex file again... Is that right? I don't know why, but I figured that the EEPROM would contain different information than the flash memory.
I clicked on input ELF file, and that seemed to work too. However, I guess I'm supposed to select all my fuses and lockbits settings first. I don't know what that means yet. Time to dig through the manual.

Nothing make my little red led flash, so I guess I need to sift through the manual some more. That's not really the point though. What I am wondering is whether or not this is an OK way of doing things. I mean, do I really _need_ the makefile to do all the programming for me? Or, can I use the makefile write the hex file etc (something I haven't accomplished yet) and then use Studio to burn the hex file to the chip? Also, why do flash memory and EEPROM receive the same hex file? Ok enough questions. I need to read more


----------



## Qer (May 7, 2008)

Make is just a tool for simplifying repetitive tasks, like compiling and linking files. It can do the programming step as well (it does for me, obviously...) but make can do as little, and as much, as you like. It's entirely up to you. So yes, you can let make create the hex-file (to be correct it doesn't really create the hex-file, it just runs the command that generates it) and then manually program the chip. Absolutely no problem there!

No, as far as I can tell the EEPROM should not be using the same hex-file, however I can't answer that question with total certainty since I've never programmed the EEPROM with an external programmer. However, I don't think that you can specify any data in the AVR-code that should be dumped to the EEPROM, if I'm not completely gaga it's completely separated from the actual program and you have to generate that data separately. Normally, all the stuff you generate go into the Flash.


----------



## xrotaryguy (Jul 26, 2007)

Thanks. 

As mentioned before, I think part of the problem is that I am using a 64 bit Vista machine. I have done some more research and evidently much of this software (Studio and winavr) does not work with my processor or my OS. Atmel recently released Studio 4.14 which is supposed to be 64 bit Vista compatible, so I am downloading that as we speak (or type rather  ). 

I don't know of a winavr version that is specifically compatible with this machine. I have found several threads exposing problems with make on 64 bit machines. I need to look into that some more and make sure that I have a version that will work for this computer.

I am also still working with my XP machine to try and get Studio to install on it. We'll see which computer works first I guess.


----------



## xrotaryguy (Jul 26, 2007)

WOO HOO!!! I finally programmed this thing. It is flashing way slower than I want, but it works.

*doin' the hoopty* lol

Here's a vid of the "action" 

http://i26.photobucket.com/albums/c126/xrotaryguy/compressorpics029.jpg


----------



## Qer (May 7, 2008)

xrotaryguy said:


> WOO HOO!!! I finally programmed this thing. It is flashing way slower than I want, but it works.
> 
> *doin' the hoopty* lol


Congrats! Great news! 

Now, admit it's a VERY special feeling watching a micro controller do fancy stuff, much more fun to see a window pop up on the screen or so. I mean, the micro controller is a black box that either works or not, much more exciting than a computer program where you can actually debug stuff. 

Speaking of debugging, here's my little way to set up a serial port:

void uart (uint32_t osc, uint32_t baud)
{
UBRR0H = (((osc * 256 / baud) - 1) / 2) >> 8;
UBRR0L = (((osc * 256 / baud) - 1) / 2) & 0xff;
UCSR0A = 1 << U2X0;
UCSR0B = 1 << TXEN0;
UCSR0C = (3 << UCSZ00) | (1 << USBS0);
}

osc is the frequency of the clock in kHz and baud is the speed you want to communicate in. Then I use this function for debug printouts:

void write_string (const char *msg)
{
char cntr = 0;
while (msg[cntr])
{
UDR0 = msg[cntr];
while (!(UCSR0A & 0x40));
UCSR0A |= 0x40;
cntr++;
}
}

Trust me when I say that things get MUCH easier when you can add trace messages to your code...

Do you have an ordinary RS232-serial port on that kit? Otherwise you need a converter from TTL-levels to RS232-levels. Something like this:

http://www.acroname.com/robotics/parts/S13-SERIAL-INT-CONN.html

I have one that connects to an ordinary RS232 9 pin connector and then I have four cables that I just connect to my prototype. See attachment for how my adapter looks. There you can also see my very simplistic programmer, it's just an ordinary printer cable that I've stripped and added connector pins to. Might be something to consider if you need to program the AVR when it's soldered into a prototype later on.

Anyway, now when you've solved the problem of setting up a working environment we're all expecting small wonders from you! Keep us posted.


----------



## xrotaryguy (Jul 26, 2007)

Ecros offers an RS232 kit for the Dragonrider, but I didn't opt for it. I guess I could solder it on if I got to the point where I needed one.

So your serial port and printout code can basically be tacked onto the end of the micro's c file so that the project will print out its code? That's neat.

I still have one programming glitch to solve. I never did get make to work properly, so I don't have a way to compile a complex jumble of .c files into a .hex file. I got my .hex file by typing the following series of commands at the C prompt. 

1.) *avr-gcc -g -Os -mmcu=atmega8 -c speedy.c*
2.) *avr-gcc -g -mmcu=atmega8 -o speedy.elf speedy.o*
3.) *avr-objcopy -j .text -j .data -O ihex speedy.elf speedy.hex

I need to get the manual out again and see what all this does. I don't think I actually used make in such a way that I can compile complex code though. That's the objective for now.
*


----------



## OHM (Jun 30, 2008)

Xrota can you tell me what the hell is going on ??

What is you aim or what induction motor are you wanting to use?

I also think someone should make cheap AC controllers for whats already available of the shelf, plenty of cheap AC industrial motors.


----------



## aeroscott (Jan 5, 2008)

OHM said:


> Xrota can you tell me what the hell is going on ??
> 
> What is you aim or what induction motor are you wanting to use?
> 
> I also think someone should make cheap AC controllers for whats already available of the shelf, plenty of cheap AC industrial motors.


lower end industrial motors need the best software because there not belt to handle harmonics , starting torque . this is helped by the more complex software . the hardware for the most part is the same .


----------



## Qer (May 7, 2008)

xrotaryguy said:


> Ecros offers an RS232 kit for the Dragonrider, but I didn't opt for it. I guess I could solder it on if I got to the point where I needed one.


Ya, it's pretty easy to solder one together. Just remember that the signal should be inverted! Simplest way is probably to use two NPN-transistors and some resistors.



xrotaryguy said:


> So your serial port and printout code can basically be tacked onto the end of the micro's c file so that the project will print out its code? That's neat.


Uh, not sure I understood what you meant, but to avoid confusion I think I better point out that the only thing this does is send strings of information through the serial port. Like:

int function_foo (int value)
{
write_string ("Entering function function_foo\n");
some code and stuff
write_string ("Leaving function function_foo\n");
}

So, nothing magical or so, just a way to send some trace messages.



xrotaryguy said:


> I still have one programming glitch to solve. I never did get make to work properly,


If you just can't get make flying, write a small bat-file instead. It's still much better than having to do stuff by hand all the time.


----------



## OHM (Jun 30, 2008)

aeroscott said:


> lower end industrial motors need the best software because there not belt to handle harmonics , starting torque . this is helped by the more complex software . the hardware for the most part is the same .


Meaning this is what is happening here? a homemade controller with sophisticated software  

by the way Xrota Im useless with anything non-userfriendly or technical as can be seen in my posts, 
yet deleted Vista as soon as I had a chance and installed Fedora 8 I´ll never go back to windoze.
Linux today is a breeze, I also like BSD which is so Open that Apple stole and modified it.


----------



## 1clue (Jul 21, 2008)

OHM said:


> Meaning this is what is happening here? a homemade controller with sophisticated software
> 
> by the way Xrota Im useless with anything non-userfriendly or technical as can be seen in my posts,
> yet deleted Vista as soon as I had a chance and installed Fedora 8 I´ll never go back to windoze.
> Linux today is a breeze, I also like BSD which is so Open that Apple stole and modified it.


Sorry for the off-topic comment, but since this is a programming thread and the controller board in question seems to have a Linux variant, AND the previous comment directly relates, I think this comment is justified.

For the record, Apple has a license to modify and sell the full-featured BSD Unix. NextStep was a fully licensed commercial variant, and Apple bought Next. The Open Source part of Mac OS is called Darwin, and it runs by itself on macs at least, but maybe on other Intel hardware as well. I haven't looked for quite a while.

http://developer.apple.com/opensource/index.html
http://developer.apple.com/documentation/Darwin/index.html

The underpinnings of Mac OS X were largely based on the Open Source BSD-Light code, I don't know how much they used from NextStep. FreeBSD's license is different from many others in ways I don't really want to get into here because that would take us WAY off topic. Even had Apple not had the NextStep license, they did nothing illegal or immoral by using FreeBSD code in a commercial product, because anyone can download the variant that they developed. FWIW, I think maybe if Microsoft would incorporate some Open Source software they would have a better product.

_Edit: _From what I remember going on on the forums at the time Apple announced their use of FreeBSD code, the OS community was ecstatic about it and very supportive. It took more than one try for Apple to come up with a license which satisfied the OS gurus, but they did eventually do it.


----------



## Qer (May 7, 2008)

1clue said:


> I think maybe if Microsoft would incorporate some Open Source software they would have a better product.


Windows support for IP-network (that is, the stuff they use today instead of that horrible IPX they used in the pre-Internet era) is taken more or less directly from BSD. And yes, the network support is one of the things that works good in Windows...


----------



## 1clue (Jul 21, 2008)

Qer said:


> Windows support for IP-network (that is, the stuff they use today instead of that horrible IPX they used in the pre-Internet era) is taken more or less directly from BSD. And yes, the network support is one of the things that works good in Windows...



Interesting. I had heard that MS used BSD's network stack, but I have no confirmation so it's pretty much hearsay.

BSD's network stack is supposed to be the best out there. If a company were to adopt anything, that would be the place to start.


When doing that sort of thing, though, you have to be careful of the license. FreeBSD's license is more open than, say the GPL which is extremely restrictive to the point of being almost viral. By restrictive I mean with respect to a commercial company integrating parts of it into a commercial product. The BSD-lite contract (at least the public part) allows this, but the GPL is restrictive enough that you have to be very careful how it's done.


----------



## Qer (May 7, 2008)

1clue said:


> Interesting. I had heard that MS used BSD's network stack, but I have no confirmation so it's pretty much hearsay.


Now we're pretty off topic, but here's something google found for me:

http://osdir.com/ml/os.bsd.india/2006-09/msg00001.html


----------



## 1clue (Jul 21, 2008)

Qer,

Yes, we're way off topic here. My last comment on the matter on this thread will be this:

You can take a perfectly mature module in one setting and put it in another (new setting), and you can get some flaws. The BSD net stack works extremely well in the BSD setting, but the years of MS networking apps out there have been made with the assumption of a MS network stack. MS's drive to keep backward compatibility way beyond reasonable limits means people have written around the bugs that existed before and even relied on them.

One thing that a more rapid development cycle (e.g. Apple) gives you is that people program to an API rather than to code that they assume will be there always. Programming to an API lets you assume it will work no matter what. That in turn makes the bug reside in a specific module, and when the bug is fixed then the problems in all the applications which use the module get fixed, assuming that everyone followed the API correctly.

In the case of the former, you get a massive list of bugs that keep showing up in bizarre locations and they never end. In the latter, nothing works at first and as soon as your new implementation gets debugged, everything suddenly works.

I'm not trying to imply that MS's code was full of bugs. Lots of OS guys try to do that. My argument with MS is in other directions.

You guys can have your thread back now, as far as I'm concerned. Qer, if we want to pursue this then let's start a new thread or even a different forum someplace.


----------



## xrotaryguy (Jul 26, 2007)

OHM said:


> Xrota can you tell me what the hell is going on ??
> 
> What is you aim or what induction motor are you wanting to use?
> 
> I also think someone should make cheap AC controllers for whats already available of the shelf, plenty of cheap AC industrial motors (ACIM).


That is exactly what I am working toward. I have a 15 hp 230/460V industrial ACIM and I am working my way toward building a variable frequency drive (VFD), a.k.a. motor speed controller for it. My system will run at 460V. 

Yes, industrial AC motors are cheap. I got this one for about $100. It will run at higher voltage which means lower amperage. Lower amperage means smaller gauge wiring that will cost less and leave the car a tad lighter. Lower amperage also means less heat generated in the motor which makes the system more efficient. Also, an ACIM has no brushes, so it requires less maintenance than a DC motor (which is already lower maintenance than a gasoline motor). The advantages go on and on.

Technically, an AC induction motor that is balanced to spin at 18,000 rpm would be better. An EV with that type of motor can be built without a transmission which decreases weight, rotating mass and friction. Unfortunately, that type of motor is about $25k with the controller, and I don't have that kind of money. Heck, even if I did, I would spend it on Li ion batteries anyway.


----------



## xrotaryguy (Jul 26, 2007)

1clue said:


> Qer, if we want to pursue this then let's start a new thread or even a different forum someplace.


Yeah, get a room!


----------



## aeroscott (Jan 5, 2008)

OHM said:


> Meaning this is what is happening here? a homemade controller with sophisticated software
> 
> by the way Xrota Im useless with anything non-userfriendly or technical as can be seen in my posts,
> yet deleted Vista as soon as I had a chance and installed Fedora 8 I´ll never go back to windoze.
> Linux today is a breeze, I also like BSD which is so Open that Apple stole and modified it.


you got it . give it some time this is all new stuff . keep reading ask questions .


----------



## OHM (Jun 30, 2008)

aeroscott said:


> you got it . give it some time this is all new stuff . keep reading ask questions .


Sorry to veer some off topic - For me free stuff that becomes retail is shifty to the point of stealing but thats just my view sorry to offend anyone.

Xrota - I missed and havent been able to find some things like:

Which brand and model motor are you using? Im looking for a lightweight 4-6pole 208-230v 15hp in alloy.

What batteries do you have in mind? 144 90-100ah lithiums or something else?

Do you know if its (i know it less efficient supposedly) possible budget wise to use something like Toyota Synergy style of setup in that you can have a lower pack voltage and run and inverter to get up to 500volts?
I know these kind of inverters are expensive but just wondering as then you could use say halve the lithiums or lead. Personally Id like to run
an alternative brand of LifePo4 that come in 100ah cells.

Last question... Are the bearings on these cheap industrial motors and issue to making higher rpm and can they be replaced with better bearings and also balancing for higher rpm? eg 5500-6000rpm


----------



## aeroscott (Jan 5, 2008)

OHM said:


> Sorry to veer some off topic - For me free stuff that becomes retail is shifty to the point of stealing but thats just my view sorry to offend anyone.
> 
> Xrota - I missed and havent been able to find some things like:
> 
> ...


US motors model S628A ,1200 rpm ( 6 pole) ,7.5 hp , about 200 lbs . will run to 6000 rpm with bearings / balancing . the possible weak spot would be the laminations need to be thin to not create heat at high cycles . it looks like they are thin . or a 1800 rpm (4 pole) 15 hp rating , type UTTE 575 volts (Canada ). I have laptop batteries so the higher the voltage the better but I need bms . synergy looks good so far . don't know about converting voltage up for LA . 230 v low voltage setting on the motors seams like lowest we can get . but that is 230 X 1.41 = 324 volts .


----------



## 1clue (Jul 21, 2008)

OHM said:


> Meaning this is what is happening here? a homemade controller with sophisticated software


Just saw this again, and have a question. If you have a lower quality motor, you evidently need a more sophisticated controller to make up for some of the problems with cheap motors.

What if you use a sophisticated controller on a getter motor? Don't you get a better result?


----------



## 1clue (Jul 21, 2008)

OHM said:


> Sorry to veer some off topic - For me free stuff that becomes retail is shifty to the point of stealing but thats just my view sorry to offend anyone.


OHM, Are you commenting on Redhat-Fedora or are you commenting on Open Source in general?



> <chop>
> Do you know if its (i know it less efficient supposedly) possible budget wise to use something like Toyota Synergy style of setup in that you can have a lower pack voltage and run and inverter to get up to 500volts?
> I know these kind of inverters are expensive but just wondering as then you could use say halve the lithiums or lead. Personally Id like to run
> an alternative brand of LifePo4 that come in 100ah cells.



It's possible to do that, but you run into the same sort of problem you would get if you have a lever that magnifies motion. You lose precision in the lever because of flexing in the materials and play in the holes.

There are lots of different sizes of batteries and cells available. It's best to find what you need and build a battery that supplies that voltage and current.


----------



## xrotaryguy (Jul 26, 2007)

OHM said:


> Sorry to veer some off topic - For me free stuff that becomes retail is shifty to the point of stealing but thats just my view sorry to offend anyone.
> 
> Xrota - I missed and havent been able to find some things like:
> 
> ...


Here is a link to the site where I am documenting the build process.

Here's a shot of the tag on the motor







> Do you know if its (i know it less efficient supposedly) possible budget wise to use something like Toyota Synergy style of setup in that you can have a lower pack voltage and run and inverter to get up to 500volts?
> I know these kind of inverters are expensive but just wondering as then you could use say halve the lithiums or lead. Personally Id like to run
> an alternative brand of LifePo4 that come in 100ah cells.


Yes, the problem that I have with this is that you lose efficiency and personally would not go that route.



> Last question... Are the bearings on these cheap industrial motors and issue to making higher rpm and can they be replaced with better bearings and also balancing for higher rpm? eg 5500-6000rpm


I don't know what the limitations of the bearings are in this motor, but I don't really care to find out. I am already building my own VFD. I don't want to reinvent too many wheels on the same project. If I do that, I probably won't get it done at all.


----------



## xrotaryguy (Jul 26, 2007)

judebert said:


> according to the Atmel site, there's a GCC available for use with AVRStudio.
> 
> I believe that's what you're looking for?


Aah, that instructional should be very helpful if I can get things to work that way. I went ahead and set up Studio to use winavr, but I did not get good results. I get this error message.


> c:/winavr-20080610/bin/../lib/gcc/avr/4.3.0/../../../../avr/lib/avr4/crtm8.o.init9+0x0): undefined reference to `main'


I looked at the C code again thinking that perhaps MAKE doesn't like something in there. The C code contains a 'main' command, but I don't know what would be wrong with it. That is the command that actually starts the program running after all the parameters are established right? Maybe my nomenclature is off, but I think that's the general idea.

Here is the portion of the C code that concerns me.



> //Main Function
> int main(void)
> {
> init_io(); //Set up the pins that control the LEDs
> ...


----------



## xrotaryguy (Jul 26, 2007)

Haha, it's funny how this site sometimes turns colons and parenthesis into emoticons when it shouldn't


----------



## Qer (May 7, 2008)

Yeah, I'd be very worried about that C-code as well. That smiley is probably the cause of your bugs. 

Seriously, make doesn't understand C, make only understands time stamps and error codes from programs. When you write a rule like:

test : test.c

it only "knows" that test depends on test.c so if test.c has a later modification date than test, it has to recompile test. If test has a later date than test.c it considers test up to date and doesn't recompile it.

If the compilation is successful it goes on to follow the next rule and so on until it encounters an error like a C-file not possible to compile due to programming errors. Then the compiler will return an error statement to make and make will stop.

Make is pretty stupid, but what it does it does good.


----------



## OHM (Jun 30, 2008)

1clue said:


> OHM, Are you commenting on Redhat-Fedora or are you commenting on Open Source in general?
> Not at all just apple taking BSD adding their bits and selling it for big bikkies.
> 
> Xrota - I wouldnt say to change the bearings just wondering thats all.
> ...


----------



## 1clue (Jul 21, 2008)

OHM said:


> 1clue said:
> 
> 
> > OHM, Are you commenting on Redhat-Fedora or are you commenting on Open Source in general?
> ...


You can download for free the part they copied from FreeBSD and modified here:
http://www.opensource.apple.com/darwinsource/

They charge for technologies that they always charged for, and the integration, packaging and technical support that they give on Darwin. You can join the open source development team and submit your patches to the source, which will be reviewed and accepted or rejected as is common in any OS project of any size.

You can also take Darwin and make your own project from it, and as long as you follow the license agreement you could sell a product which incorporates the OS software. You can't charge for the software itself, but you could charge for a service contract or for the work involved in integrating the OS software with other products. Apple's agreement may be more or less liberal than that, I haven't read their agreement. However it did pass muster with the Open Source community at large.


----------



## 1clue (Jul 21, 2008)

I made an Open Source thread here:
http://www.diyelectriccar.com/forums...ion-18993.html

I'll post this link in a few other places where OS discussions have distracted the main topic somewhat. Please post open source comments there which do not directly pertain to this specific project. This is as much for me to stay out of trouble as for anyone else.


----------



## OHM (Jun 30, 2008)

Xrota - I wouldnt say to change the bearings just wondering thats all.
But love your motor especially that old skool guage looks really steampunk cool. Can you still get that motor?

On another note can the Azure dynamics controller be used on such a motor?


----------



## xrotaryguy (Jul 26, 2007)

OHM, I don't know how well the Asure Dynamics controller would work on this motor. Technically, it certainly could work, but I don't think that it would work on this motor unless the motor had a reluctor and a pair of inductive pick-ups added. That's how Asure's old controller worked. I've heard that they're coming out with a new unit and I suspect that it will be able to intuit motor velocity and other characteristics without the added hardware. 

I don't know if I will be fabricating a reluctor and hall sensor setup for my controller/motor or not. I am more or less going where the lowest price takes me. I'm also in a bit of a hurry, so I will probably just build what ever I figure out first.


I finally figured out how to use winavr with Studio 4.14. this means that I can now start compiling larger more complex programs. Mission accomplished as our fearless leader would say. I am starting a C++ class in one week. Hopefully that will get me sufficiently up to speed so that I can start modifying code and building a controller.

Thank you thank you thank you to everyone who posted helpful links and who helped me figure this out in general. My goal was to figure out how to burn a microcontroller before the summer's end, and with your help, I did just that. I could not have done it without you guys.

Let the good times roll!


----------

