![]() ![]() Other words it generates its own high/low gate signals with appropriateĭead-time automatically generated - without this you'd need some ![]() It relies on having an inverter module that takes one input per phase (in I've realised the Mega has some timers with 3 output pins, and this allows aĬlever way to modulate 3 output signals for doing this. I've been thinking about this some more and looking at what the Arduino This can work with actual current feedback from the inverter as well as with Is simpler but needs to run even faster for good smooth sinusoid response. On a regular clock tick and change the output pattern based on the error - this There is another approach, hysteresis drive, where you examine the error The the right pattern (pin-change interrupts can handle that).ĥ0kHz is ambitious, thinking about it, on a 328 based board at least. Pins if you use the hardware, and you then need to read these pins and convert The problem this gives is that each PWM period needs to split into 3 parts,Ģ different drive patterns and a zero-drive part. Six drive patterns arranged around a hexagon in phasor-space. Think of the 8 inverter drive states as two zero-drives (all phases the same), and ![]() Two active drive states (and the zero drive state). I think with a little care you can use the currentĪngle within the current 60-degree sector to determine the ratio of time spent in If you are driving an inverter the output signals are not independent though, and for To generate 1kHz sine wave you probably want to run your PWM at something like Enable phase correct PWM, TOP at OCR2A (OCR2A determines frequency)Īfter you've done this, writing a value between 0 and 166 to OCR2B should give you between 0% and 100% duty-cycle respectively. ![]() Set the pin mode to output and make it low when we're not sending PWM If you use phase correct PWM, which you may need for your application, then the frequency is divided by 2 again (since fast PWM counts up only and phase correct PWM counts both up and down) - there's a good explanation of all this here: Īny, top stop with the rambling, I think you should be using some code very much like the following: int pwm_pin = 3 The possible values for the prescaler are given in the datasheet I linked to and the most appropriate for your case appears to be 64. Since the limit has a maximum value of 255 for TIMER2, you'll need a prescaler value that gives you a value for limit less than 256 and ideally as large as possible within that range to allow maximum precision of control. So if you want a frequency of 1500 Hz you'll need (limit * prescaler) = (16000000 / 1500) Basically, the clock frequency (16MHz) is divided by (TOP limit * prescaler) to give the frequency of the timer. The key with using custom PWM frequencies is to work out the correct value for the TOP limit register and the prescaler. I've had a quick look at the ATmega1280 datasheet and everything seems to be the same with regard to this, so hopefully it will work fine on your board. This code has been used on the ATmega328P (Arduino Duemilanove) but shouldn't require any modification - it should just work but I can't guarantee anything. The code I'm posting has been used to generate a 38KHz carrier for IR remote control but I have adapted it for use generating much lower frequencies, e.g. You should be able to set up PWM at whatever frequency you like quite easily using the ATmega's 8-bit TIMER2. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |