View Single Post
Old 05-12-2013, 05:02 PM   #8 (permalink)
jyanof
Joe
 
Join Date: Feb 2009
Location: phx
Posts: 260
Thanks: 0
Thanked 48 Times in 38 Posts
basics of the code

Code:

The software is mostly interrupt based with a few fault checks occuring during the main loop.

The first part of the main routine begins with the array for storing the sine wave values. There were a few values that are really close to full on (100% duty cycle) so those values are replaced with 511 for full on.

The 'waitforprecharge' subroutine will wait for the voltage in the large cap to first rise to about 135V, then it waits until the change in ADC reading as a sample is read every second changes by less than 3.

The repeating part of the main routine first has some LED toggle code (I added an LED to one of the ISP pins) and then some code to start the motor when the user flips the switch. The start sequence initializes the frequency and voltage outputs, then waits for the boost voltage to nearly reach the boost voltage setting (while checking to make sure the battery didn't get disconnected or that the control switch went off, then turns on the clutch. lastly, there's a few fault checks.

The timer1 overflow interrupt handles all of the timing based stuff, mainly updating the output PWM to mimic a sine wave and selecting, reading, and processing ADC conversions.

The variable 'currentscalar' will change the frequency and magnitude of the output voltage (as a V/F relationship) depending on its value. the frequency is affected by modifying how the PWM array index is updated and the magnitude is affected by a simple scalar when calculating the actual OCR1B value.

The complete start sequence starts with a currentscalar of 24 (24 over 128, really). There is also a 'start' variable that forces the output ratio to start at 50% output (32 over 64). Also, the boost converter stays off at first, so the input voltage to the h-bridge is the pack voltage, about 150V. once the output has reached full frequency (currentscalar of 128), the start variable is incremented until the full output voltage is applied. Finally, once the start variable has finished incrementing, the boost voltage is set to the high voltage, about 315V.

To stop the motor, the clutch is commanded open at the same time the boost converter is turned off. Since the clutch doesn't open right away, this has the effect of draining the large cap for a few cycles. This is beneficial since the act of unloading the motor and slowing the motor down will actually charge the cap back up, so stopping the boost converter early will prevent the cap from over-volting.

This interrupt also handles the ADC conversions. With the way the clocks and timers are set up, an ADC conversion takes longer than one PWM cycle. Thus, ADC conversions are started every other time the interrupt occurs. The ADC channels cycle through the 2 current sensors and the boost output voltage. Twice a second, instead of the boost current, either the vent temp sensor or IGBT temp is measured.

the code is attached - change the file extension to .c instead of .zip
Attached Files
File Type: zip ACinverter_c_code.zip (14.3 KB, 112 views)
__________________
ReVolt AZ testing thread:

http://ecomodder.com/forum/showthrea...ting-9325.html
  Reply With Quote