Is Javalin fast enough for 3ph AC PWM?
I have been trying to use PWM function and generate AC signal by using pwm.update(). I have to be running at least 3 PWM PVs and update them at least 12 times in one 60Hz cycle to get the desired output.
I'm just trying to come up with the Java code for the simplest and fastest method of doing that, but my gut tells me Javalin is not fast enough to handle all 3 of them at the same time.
here is what it will look like for one phase:
the phases 2 and 3 are going to be the same way, but they will be updated with a 120 degree angle apart from phase1 (possibly using a timer).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
Post Edited (Ali E.) : 2/14/2007 2:46:24 AM GMT
I'm just trying to come up with the Java code for the simplest and fastest method of doing that, but my gut tells me Javalin is not fast enough to handle all 3 of them at the same time.
here is what it will look like for one phase:
PWM phase1 = new PWM(some_pin); timer tmr=new timer(); ... byte i=0; while (true) { if (timer.timeout(slot-time)) { lowtime = table[noparse][[/noparse]i++]; phase1.update(max - lowtime, lowtime); if (i==n_slots) i=0; }
the phases 2 and 3 are going to be the same way, but they will be updated with a 120 degree angle apart from phase1 (possibly using a timer).
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
Post Edited (Ali E.) : 2/14/2007 2:46:24 AM GMT
Comments
The pwm frequency is defined by a high period and low period (both in 8.68usec units).
Minimum period is 2*8.68usec = 17.36 usec ->fmax =·57604 Hz
Maximum period is 2*255*8.68usec = 4426.8 usec -> fmin = 226 Hz
regards peter
All the power circuit is taken care of (and is already built) using International Rectifier's IR2233 and a 3phase IGBT. All we need are PWM and PWM inverted signals with a little dead-time in between (I'm thinking of using an inverter and a buffer for the delay, so we don't have to generate 6 PWMs on the microcontroller).
There is a fault detection and shutdown signal coming from IR2233 and we can arrange something for that after we got our PWM working.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
Oh I see what you mean. Let me explain a little more.
Our PWM will be updated using PWM.update(high, low); and the high and low need to be varying by Sine function. Since we cannot process Sine on Javalin (or in fact any Microcontroller that i have ever used before) we can use a lookup table. Just to make that even more optimized we are trying to use the timer function and update pwm...
Here is our approach:
- we have a lookup table of times to change the duty cycle depending on the frequency in an array (for example we have an array of 60 elements from table[noparse][[/noparse]0] to table [noparse][[/noparse]60] corresponding to the delay before changing the duty cycle for each frequency from 0Hz to 60Hz.
- the frequency we want to generate is known. so we have a while loop, we have a timer, and we update when the timer reaches the value for that frequency.
- delay a little bit before generating the same signal for phase 2 (120 degree difference for phase) and then delay a bit more then start generating Phase 3. I think theoratically this should work if implemented.
But looking at the sample code fragment at the top I'm thinking that Javalin will be really busy doing that. we need real-time performance or we will run into trouble with the induction motor.
I hope that clear things up a bit... This is so hard to explain in writing...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
http://www.htsoft.com/forum/all/showflat.php/Cat/0/Number/7000/an//page//vc/1
regards peter
·
I have some majour understanding issues about Javalin and Java on it... I just have trouble understanding what does what. I guess for an average guru that does not matter as long as it works, but when it comes to optimization ??? I guess an average user will not need to care.
Is Javalin's timer() invoke an interrupt routine or something?
I still have trouble understanding how 6 VP's can be loaded at the same time and if they require CPU time does that mean they are time sharing? Is there some sort of OS on Javalin that takes care of that? (am i thinking about it too much?)
Is there a tool that can convert JAVA to Assembly for Javalin (not that I care to program in asm, but just to have an idea of how many clock cycles things take to run). Or is there a way that i can analyze the speed for running the code or CPU utilization or something that can help optimize the Java code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
This ISR is executed·once every·8.68usec. For the Timer VP, a 32bit counter is
simply incremented.
VP's native code do require time. The maximum time spend inside the ISR is 217 cycles
out of 256 cycles. (25MHz*8.68usec = 217, Crystal frequency is 25MHz).
The more VP's you execute simultaneously, the more time is spent inside the ISR,
with a maximum of 217 cycles (each cycle is 40 nanoseconds).
When you use t.mark() the current value of the 32bit timer count is stored privately
for the object t.·When you use t.timeout(msvalue) the method timeout() calculates
the stop count based on the stored count and the msvalue. It returns true if
the·current count is beyond the stop count.·This calculation is done everytime
you use t.timeout(), which is frequently.
Consider my ScaledTimerTimer16 class. It·has a mark(msvalue) method. This also stores
the current count but also calculates the stop count. The timeout() method now
just compares the current count against the calculated stop count which saves
quite a bit of time considered mark() is called less frequently than timeout().
There is no tool to run your own native code.
regards peter
Where can I find ScaledTimerTimer16 class?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
regards peter
However I have to implement the phases 2 and 3 as well and use a timer to have them started 120 degree apart from each other. On the other hand the way it is implemented now i will need two more timers for phases 2 and 3 as well. That leaves me with no more resources and VP's left. Is there a better way of doing it instead of the way it is done here?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
Post Edited (Ali E.) : 2/17/2007 9:36:11 PM GMT
So you can have timers plus 5 other type of vp running.
Edit: don't you mean hightime[noparse][[/noparse]i] in your code, as hightime is an array?
Also better to define hightime as an array of int, to prevent possible
sign extensions to int during calculations.
regards peter
Post Edited (Peter Verkaik) : 2/17/2007 9:52:39 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
for example
······if·(time1.timeout())·{
···········phase1.update(HighTime[noparse][[/noparse]i1],·26-HighTime[noparse][[/noparse]i1]);
···········time1.mark();
···········i1++;
······}
······if·(i1·==·19)·i1=0;
can be replaced by
······if·(time1.timeout())·{
···········phase1.update(HighTime[noparse][[/noparse]i1],·26-HighTime[noparse][[/noparse]i1]);
···········time1.mark();
···········i1++;
·········· if·(i1·==·19)·i1=0;
······}
or
······if·(time1.timeout())·{
···········phase1.update(HighTime[noparse][[/noparse]i1%=19],·26-HighTime[noparse][[/noparse]i1]);
···········time1.mark();
···········i1++;
······}
so you don't need to test for i out of range each loop, but only when i increments.
regards peter
Post Edited (Peter Verkaik) : 2/17/2007 11:58:09 PM GMT
I'll be back to the lab tomorrow morning and give it a shot right away. However I've got to see why Javalin goes non-responsive after about 30sec or so. Is it because it heats up? I dared to touch the chip to see if it was hot... it did feel worm, but not particularly hot. Is there a possible memory leak or something in my program with all the variables being tossed around?
That is aside from the fact that I did get the perfect 3phase output... It was absolutely clean and noise free signal. It was so beautiful on the digital oscilloscope that almost brought tears to my eyes!!!
I wish Javalin was about 200Mhz faster and had more ram tho (maybe I'll give the new Propeller things a shot, even thou that is going to be a majour overkill and waste of money and time for this project). Is there going to be a Java Interpreter for Propeller? sometime in the future maybe? or in someone's head at least?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
ok... now Javalin is running, but with lots of glitches. It actually stops working after a while. There seem to be no pattern to it. Sometimes it runs for 2 to 3 min, sometimes it craps out after 10 to 15 sec.
Another issue is that the output frequency is not even up to speed. In fact Pase 1 and Pase 3 (pins 1 and 3) are faster than phase 2 (pin 2). I don't seem to get what is going on. Is there really no hope of having this done on Javalin?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
You don't know when a timer has expired until you call timeout(), so basically
you are always too late with updating. You could be busy updating the pwm for phase1
when the timer for phase3 expires, but you won't know that until you reach
the code for phase3.
The following approach may be more useful.
static int[noparse]/noparse sine = new int[noparse][[/noparse]360]; //table with sinevalues for whole degrees
//128 equals sin(0), 128+120 equals sin(90), 128 equals sin(180), 128-120 equals sin(270)
//the table holds a sine with dc offset 128 and amplitude 120
static·DAC phase1·=·new·DAC(CPU.pin1);
static·DAC·phase2·=·new·DAC(CPU.pin2);
static·DAC phase3·=·new·DAC(CPU.pin3);
static int angle=0;
static int p1=0; //phase1 start angle
static int p2 = 120; //phase2 start angle
static int p3 = 240; //phase3 start angle
static void main() {
· while (true) {
·· ·phase1.update(sine[noparse][[/noparse](angle+p1)%360]);
··· phase2.update(sine[noparse][[/noparse](angle+p2)%360]);
··· phase3.update(sine[noparse][[/noparse](angle+p3)%360]);
····angle = (angle+1)%360;
··· CPU.delay(160); //delay determines time to advance 1 degree, ie. sine frequency
· }
}
The above has the advantage that the while (true) loop has a constant loop time
which ensures the DACs are updated at regular time intervals.
Check the waveforms at pins 1 to 3 on a scope and find out the appropiate delay values
for the frequencies you desire. If you assume the updates take no time, then you
can calculate the delay from the desired frequency.
F = 1/(360*Tdelay) or Tdelay = 1/(360*F)
Ndelay = Tdelay/8.68usec = 1000000/(8.68*360*F) with F in Herz
use CPU.delay(Ndelay) in the code above
regards peter
thanks a lot for the reply. The program actually works but the output signal is not PWM (Pulse Width Modulation) but it is Frequency Modulation. PWM has constant period but duty cycle changes. FM has variable period. I can generate the perfect Sine wave using DAC circuit thou. This program works very accurately if you need a low voltage, slow, and low power 3-phase sine output.
But that sine wave is till neither fast nor powerful enough to run an induction motor. The fastest sine frequency output i got (without the delay line) was about 0.5Hz.
This means that Javalin needs to be more than 100 times faster to get 50Hz output to make that somewhat useful in Europe and Asia? It needs to be even faster to make that run 60Hz at no delay.
Javalin seems to run for at least 30min without crapping out!!! that is some good news for me since i was worried there might have been some hardware problems with the Javalin that caused it to freeze and the output stopped after some random period of time. I think out program is just too much for Javalin to process.
I need another microcontroller fast!!!
Any good Java programmers here that could tell me if it was possible to generate that kind out output from parallel port on a PC? (That is the fastest microcontroller that i have right now, that I may turn into using). Oh man... my partners won't like this!!! I'm dead!!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
GAME OF FUTURE INC.
Unleas Your Imagination, See the Future
www.gameoffuture.com
I used 360 entries, but even 20 or 10 would do. Each loop then advances 18 degrees
instead of 1.
You could replace the DAC by PWM. The point I tried to make is that you
need a constant loop time. So instead of your table with time delays when to do
a next update, use a table with dutycycle change for a fixed time to update (eg. the looptime).
That way you don't neeed all the timers and don't need to check for conditions.
regards peter
Post Edited (Peter Verkaik) : 2/19/2007 10:54:00 PM GMT