Converting WinAVR to arduino

Some people have told me that this program will work in arduino but I just can't seem to get it to work does anyone have any ideas?
http://www.zerogasoline.com/images/stories/cougarcontroller/HighVoltageControllerIMPROVED_ECOM.C

Some people have told me that this program will work in arduino

People that should know?

but I just can't seem to get it to work

Bummer.

does anyone have any ideas?

Yes. Tell us what you expect that program to do, what it actually does, and how that differs from what you want.

Not a software guru, but that looks like a 'classic' C program because it uses:

int main (void) {

The Arduino preprocessor supplies it's own init and main functions. You will have to convert any init statments inside a:

void setup()
 {                
  // put initialize code here.        
 }

And convert anything inside your main function into:

void loop()
 {
  // put your main function statements into here
 }

Lefty

I'm assuming by "this program will work in arduino" you mean that it can be compiled using the
arduino IDE and then downloaded to the AVR.

Since the code is not using anything arduino, and as long as you don't intend to ever call any arduino functions
in the future, simply change the extension of your file from .c to .pde and you should be good to go.
The IDE will happily compile it and the linker will not pull in the main() from the arduino core library but
use your main() instead. That way there is no need/use for the setup() and loop() functions.

As long as the AVR has a compatible bootloader and the board with the AVR being programmed
has the serial port auto reset circuitry in place, the IDE will also be able to download the code as well.

But honestly, if I weren't using anything arduino in the code, I'd stay away from the arduino IDE as well.
Use straight makefiles or if using windows, use the AVR studio gui which can do the compiles and
even source level debug if you have the appropriate ISP/JTAG programmer.

--- bill

This is a motor controller code for an EV. Yes that is correct it won't compile. Where is the extension of the file .c .pde or otherwise? What I am trying to do is just copy and paste from that link right to a new arduino sketch and its not working. The first error that comes up is UBRRH was not declared in this scope.How do I use makefiles?

But is "compiling" just fine. The code simply won't compile without errors "as is".
Changing to makefiles isn't going to help that.
It appears to have been written for a different processor that uses different i/o register define names.
Maybe it was originally for a atmega16 or 2313 and now you are trying
to compile it for a m328p ?

You will need either create mapping macros to map the currently used define names to the appropriate names
on the new processor or change the code to use the appropriate names.
(Would have been nice if the AVR system io files simply mapped the old names to the new new names assuming
the '0' entry when there are more than one for portability ---- But they didn't)

Example.
UBRRH on a m328p would be UBRR0H
TXEN is TXEN0
UDR is UDR0
TIMSK could be TIMSK0, TIMSK1, or TIMSK2 depending on which one you use/need.

These defines are in the io header for the processor. For a m328p they will be in
{installdir}/avr/include/avr/iom328p.h

--- bill

Hmm.. Is there some sort of glossary where I can find all the register define names and the arduino translations?

Normally if an arduino sketch code is being written, no AVR registers will ever be used.
It is only when trying to do something that is not provided for by the arduino core library code
(or one of the provided libraries)
that you must step outside of the arduino environment and talk to the AVR registers directly.

In your case, you are trying to completely bypass the arduino environment and its libraries entirely
to use the IDE to compile non arduino code.
Since your code is totally outside the arduino environment nothing has to be translated for arduino.
The AVR register names are the AVR register names as the arduino IDE uses the avr-gcc compiler package
and the avr-gcc header files define all the registers.
You can see all the names/defines in the header file I mentioned above
and you will find that they all match the names in the atmel avr datasheet for the given processor
which makes it easy to "guess" the define/register name from reading the atmel datasheet documentation.

You still haven't said which AVR processor the code was originally written for or
what AVR you are now using, but you can find the documentation for all them on the Atmel site.
Here is the link for the 328p part:

You can find all the register names in the summary doc but you may need to consult the full document to read a bit more about
the registers to learn more.

But I'm guessing that you will probably need to know more than just the new register names since you
may have to tweak some of the code a bit before its all done.

--- bill

I am using an atmel 168 and so is he but I have a lot of 328's I might want to use those. This is the chip that he ships out http://mouser.com/ProductDetail/Atmel/ATmega168-20PU/?qs=aqrrBurbvGdMdllC0pUwIg%3D%3D I think he is using avr studio with an avrisp mk2 programmer. I hope this tells you something. :~

INFOWARRIOR:
I am using an atmel 168 and so is he but I have a lot of 328's I might want to use those. This is the chip that he ships out http://mouser.com/ProductDetail/Atmel/ATmega168-20PU/?qs=aqrrBurbvGdMdllC0pUwIg%3D%3D I think he is using avr studio with an avrisp mk2 programmer. I hope this tells you something. :~

In your posts there are several things like:
Some people have told me
I think he is using
that creates some concern for me especially since this looks like it might be code
for a controller for some sort of electric vehicle.

To me it appears that the code that you have is not written for the part you are trying to use.
It compiles just fine for the atmega16 and atmega8 so in my view this is not an issue of toolsets.
While the mega8 and the mega168/328 are pin compatible the registers names used at the
source code level are not the same and like I mentioned above will need to mapped to the new
names or the code altered for the new names.

There are also some busy delays in the code that appear to have some exact delay requirements.
The delay routines as written do not take into consideration the cpu clock rate
(they appear to assume 8Mhz), but more importantly they will optimized away to nothing (zero delay) depending
on the compiler optimization options chosen, so compiler options, as well as compiler versions may be very critical to
this code working properly.

Here is a link to a svn tree to what appears to be a project using the same/similar code
(I say similar because it is a bit different from your version of the module)
http://svn.fastdigitech.ro/trac/openrevolt/browser/trunk
It includes some files for using with avr studio, which I don't use, but appears to
be compiling the code for the mega8. It also appears to be compiling with -Os which will turn on
the optimizer which will break the Delay() routine in HighVoltageControllerIMPROVED.c
(HighVoltageController.c attempts to use volatiles to avoid this issue)

I think you should talk directly to the author about the code, how to properly build it, exactly what AVR parts are being used
and the speed at which they need to run.
Here is a possible link to the contacts for the code you have:

--- bill