Arduino Electric Car

Hay All I am a bit perplexed, as yesterday I received my new arduino DUE. I am in the process of redesigning my three phase hex inverter that runs my EV. The first one was built on radioshack craft bords and had a couple of design flaws that seemed to work ok in the beginning but ended badly. I purchased the DUE form mp3car.com who delivered very quickly, Thank You mp3car.com I am attempting to modify my code to run on the DUE however I am having difficulty figuring out how to set the PWM frequency to ~4000 or so. The project can be viewed at evmaker.tumblr.com. If you go back several pages there are some videos of the truck driving around under the control of a mega2560. One of the shortcomings is that the 2560 is not fast enough to play 60 samples of sine and do all the speed and voltage calculations fast enough to run the motor at a reasonable rpm. If someone could please help with the PWM frequency adjustment for DUE I should be back rolling by Dec with my new solid inverter drive.

You can reset the prescale divide ratio for each timer - by default they are all set to divide-by-128 I think. Also timer0 is set to fast-PWM mode (256 prescaled-clocks per cycle) and timers 1 and 2 are set to phase-correct PWM mode which takes 510 prescaled-clocks per cycle.

Direct register manipulation can be used to reprogram the scaling factors and PWM modes for each timer. timer0 should be left as-is if you want delay(),micros() and millis() to work.

I’ve some rudimentary notes on the timers at http://www.mythic-beasts.com/~markt/ATmega-timers.html
(the definitive source is the ATmega328 datasheet though: http://www.atmel.com/Images/doc8161.pdf )

there is a good writeup with a name like "secrets ofarduino PWM" or somethinglike that, a searchshould turn it up fairly quick and explain everything clear enough that the datasheet starts making sense.

Thank you Mark T, and Noob,

I have no problem manipulating PWM on the ATmega on the mega2560. All of those recommended docks deal with the AVR series processors. I need the same sort of info for the sam3 on the arduino DUE. The thing that I am after is the sam3 on the DUE runs at a faster speed than the AVR on the mega2560. The mega2560 has no problem doing as i ask, he just cant execute enough instruction per second. The sam3 on the DUE seems to execute ten fold or so. The at mega2560 will run my 3 phase motor playing 60 or so samples of sine at 19 Hz to the motor in my truck. This was good enough for proof of concept but i need to have a faster processor to run at 60 or 80 Hz to achieve a reasonable top speed also I would like to play 180 samples of sine. The DUE has no problem doing this. I need to have pwm running at at least 4000 Hz for 60 samples 60 samples of sine times 60 times a second is 3600 slices of time. 4000 allows for some overhead. To play the 180 samples i need three times the pwm freq. 12000 Hz.