Hi all, I'm totally new to Arduino land so bear with me.
I want to control a single phase inverter (H-bridge configuration) with an Arduino using Sinusoidal PWM. Specifically, I want to use bi-polar switching, so I need to compare a triangle wave to a sine wave, and whenever Vsine > Vtri, two MOSFETs will be 'on', and when Vsine < Vtri, those two MOSFETs will be 'off' and another two are 'on'. After doing some research I have a couple of ideas about how to go about this:
Use one of the timers in Phase-Correct PWM mode since this is already essentially a triangle wave, and change one of the OCRs to act as a sine wave using a lookup table. I think that's kind of what's happening here: http://arduino.cc/forum/index.php/topic,93691.0.html, except I wouldn't want to filter the output but rather control the switches with the pulsed output.
Use two lookup tables and just manually compare values, using a delay function to get somewhere near the desired frequencies. Just use normal digital outputs instead of the built-in PWM function.
Do any more experienced users have any thoughts on which of these methods would be better, or just the general feasibility of each? Since I am such a beginner I am more looking for ideas of how to proceed, rather than specific code.
I also have a more specific question about the frequencies. The frequency of the triangle wave needs to be much higher than that of the sine wave (on the order of 1k -10k times faster). To avoid having a sine lookup table with 10,000 values in it, the resolution of the sine wave will have to be a lot worse than the triangle wave. Will this be a problem for the inverter?
Thanks for the link. I am just learning about the interrupts; can you tell me why it was necessary to disable the interrupt on Timer 0? Is there a way to do this without disabling the delay() function?
To further expand on my last question - why is it necessary to use the interrupt function at all? Couldn't you have the phase accumulator reset without that? I guess I don't fully understand what the interrupt is doing here.
To further expand on my last question - why is it necessary to use the interrupt function at all?
Interrupt subroutine with TIMER2 create "TimeBase" or primary oscillator for generator. There is no other way to ensure freq. accuracy and stability of this generator.
TIMER0 firing its own interrupt events would create a jitter or interference for TIMER2. May be it would not be a problem with low freq., 1 - 10 kHz, but as interference could take 2 - 5 usec, it would shift half a period on 100 kHz, making H-bridge impossible to operate.
cayleigh:
Thanks for the link. I am just learning about the interrupts; can you tell me why it was necessary to disable the interrupt on Timer 0? Is there a way to do this without disabling the delay() function?
Thanks,
Cayleigh
Because the interrupts for timer0 are higher priority than for the other timers and put jitter onto the signal. A lower priority interrupt handler only runs when no higher priority interrupt is being serviced, and are thus delayed when interrupts clash. In theory you could rewrite the timer0 interrupt handler to perform both DDS and Arduino timer functions.
Thanks, I think I understand now. I'm pretty sure I'm going to need a delay function - because of the MOSFET turn on/off times it's necessary to add a slight delay to ensure that they do not short circuit. (MOSFETs 1 and 2 should never be on at the same time as 3 and 4).
So can I program my own delay function into timer 2? In the scenario you mentioned where timer 0 performs the DDS and the other timer functions, does the fact that they are both operating on the same timer eliminate the jitter issue? If so it seems like just programming the DDS into timer 0 would be the way to go. Any suggestions you might have for the best way to implement this would be awesome. I think once I have a game plan I can figure out how to code it; the hard part is figuring out the best approach.
Thanks for being patient with me... I know it's a rather ambitious first project.
Have you completed your H-bridge control yet using the DUE? I am working on a very similar project currently and running into the same issues with DDS and SPWM.