I found this code at this link to generate 3 phases square wave but the sequences is not correct could you please do correction, thanks
What sequences does the code produce now?
Why is that incorrect?
What should the sequences be?
We not mind readers. And we aren't your on-call service for correcting code, for that matter.
But if we were, we'd need to know what you are aiming for.
a7
@alto777
I am doing some tests on three phases so I want a working code that can generate 3 phases as square waves because I do not want to deal with direct AC 3 phases so I want to let arduino uno generate 3 phases as square waves is there any working code to start
What is wrong with the code in the thread you linked?
Can you draw a timing diagram of the signals you are trying to synthesize?
a7
have a look at 3-phase-inverter-using-igbt-to-convert-dc-to-ac-voltage
may give you some ideas
@horace
by the way, did you find the mistake from above picture?
Looks correct to me. What were you expecting?
we have now three square wave so how to know where is R & Y & B then if make mistake by connection so want to know by display on LCD or by LED
@moderator can I add new topic ?
Someone doesn't know that 'delay()' takes an integer argument. Using 'delayMicroseconds()' gives better resolution.
Here is a sketch I picked up somewhere that purports to generate three-phase 50 Hz.
const byte pwm1 = 4;
const byte pwm2 = 5;
const byte pwm3 = 6;
void setup()
{
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(pwm3, OUTPUT);
}
void loop()
{
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(100);
digitalWrite(pwm2, LOW);
delayMicroseconds(456);
digitalWrite(pwm1, LOW);
delayMicroseconds(345);
digitalWrite(pwm3, LOW);
delayMicroseconds(209);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(20);
digitalWrite(pwm2, LOW);
delayMicroseconds(730);
digitalWrite(pwm1, LOW);
digitalWrite(pwm3, LOW);
delayMicroseconds(359);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(100);
digitalWrite(pwm2, LOW);
delayMicroseconds(454);
digitalWrite(pwm3, LOW);
delayMicroseconds(346);
digitalWrite(pwm1, LOW);
delayMicroseconds(210);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(210);
digitalWrite(pwm2, LOW);
delayMicroseconds(345);
digitalWrite(pwm3, LOW);
delayMicroseconds(455);
digitalWrite(pwm1, LOW);
delayMicroseconds(99);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(358);
digitalWrite(pwm3, LOW);
digitalWrite(pwm2, LOW);
delayMicroseconds(730);
digitalWrite(pwm1, LOW);
delayMicroseconds(19);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(208);
digitalWrite(pwm3, LOW);
delayMicroseconds(346);
digitalWrite(pwm2, LOW);
delayMicroseconds(456);
digitalWrite(pwm1, LOW);
delayMicroseconds(99);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(99);
digitalWrite(pwm3, LOW);
delayMicroseconds(457);
digitalWrite(pwm2, LOW);
delayMicroseconds(345);
digitalWrite(pwm1, LOW);
delayMicroseconds(209);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
delayMicroseconds(19);
digitalWrite(pwm3, LOW);
delayMicroseconds(731);
digitalWrite(pwm2, LOW);
digitalWrite(pwm1, LOW);
delayMicroseconds(359);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
delayMicroseconds(99);
digitalWrite(pwm3, LOW);
delayMicroseconds(455);
digitalWrite(pwm1, LOW);
delayMicroseconds(346);
digitalWrite(pwm2, LOW);
delayMicroseconds(210);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(210);
digitalWrite(pwm3, LOW);
delayMicroseconds(346);
digitalWrite(pwm1, LOW);
delayMicroseconds(455);
digitalWrite(pwm2, LOW);
delayMicroseconds(99);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(359);
digitalWrite(pwm1, LOW);
digitalWrite(pwm3, LOW);
delayMicroseconds(731);
digitalWrite(pwm2, LOW);
delayMicroseconds(19);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
delayMicroseconds(209);
digitalWrite(pwm1, LOW);
delayMicroseconds(345);
digitalWrite(pwm3, LOW);
delayMicroseconds(457);
digitalWrite(pwm2, LOW);
delayMicroseconds(99);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(99);
digitalWrite(pwm1, LOW);
delayMicroseconds(456);
digitalWrite(pwm3, LOW);
delayMicroseconds(346);
digitalWrite(pwm2, LOW);
delayMicroseconds(208);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(19);
digitalWrite(pwm1, LOW);
delayMicroseconds(730);
digitalWrite(pwm3, LOW);
digitalWrite(pwm2, LOW);
delayMicroseconds(358);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(99);
digitalWrite(pwm1, LOW);
delayMicroseconds(455);
digitalWrite(pwm2, LOW);
delayMicroseconds(345);
digitalWrite(pwm3, LOW);
delayMicroseconds(210);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
digitalWrite(pwm2, HIGH);
delayMicroseconds(210);
digitalWrite(pwm1, LOW);
delayMicroseconds(346);
digitalWrite(pwm2, LOW);
delayMicroseconds(454);
digitalWrite(pwm3, LOW);
delayMicroseconds(100);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
delayMicroseconds(359);
digitalWrite(pwm2, LOW);
digitalWrite(pwm1, LOW);
delayMicroseconds(730);
digitalWrite(pwm3, LOW);
delayMicroseconds(20);
digitalWrite(pwm2, HIGH);
digitalWrite(pwm3, HIGH);
digitalWrite(pwm1, HIGH);
delayMicroseconds(209);
digitalWrite(pwm2, LOW);
delayMicroseconds(345);
digitalWrite(pwm1, LOW);
delayMicroseconds(456);
digitalWrite(pwm3, LOW);
delayMicroseconds(100);
}
@johnwasser
do you have any idea, how to display the connections of 3 phases in order on lcd or serial monitor?
Here is a simpler version that is more likely to work:
constexpr unsigned Frequency = 50;
const byte Phase0Pin = 4;
const byte Phase120Pin = 5;
const byte Phase240Pin = 6;
constexpr unsigned long FullCycleMicroseconds = (1000000ul / Frequency);
constexpr unsigned long AdjustedMicroseconds = FullCycleMicroseconds - 40; // Adjust here for loop overhead
constexpr unsigned long HalfPhaseShift = AdjustedMicroseconds / 6;
void setup()
{
// initialize digital pin Phase0Pin,Phase120Pin&Phase60Pin as an output.
pinMode(Phase0Pin, OUTPUT);
pinMode(Phase120Pin, OUTPUT);
pinMode(Phase240Pin, OUTPUT);
digitalWrite(Phase0Pin, LOW);
digitalWrite(Phase120Pin, LOW);
digitalWrite(Phase240Pin, LOW);
}
void loop()
{
digitalWrite(Phase0Pin, HIGH);
delayMicroseconds(HalfPhaseShift);
digitalWrite(Phase240Pin, LOW);
delayMicroseconds(HalfPhaseShift);
digitalWrite(Phase120Pin, HIGH);
delayMicroseconds(HalfPhaseShift);
digitalWrite(Phase0Pin, LOW);
delayMicroseconds(HalfPhaseShift);
digitalWrite(Phase240Pin, HIGH);
delayMicroseconds(HalfPhaseShift);
digitalWrite(Phase120Pin, LOW);
delayMicroseconds(HalfPhaseShift);
}
I don't understand what you mean by "the connections". Can you show an example of the kind of output you want? Note that displaying on an LCD or Serial Monitor takes significant time so you probably can't output 50 Hz software PWM and display output.
@johnwasser
I want to check 3 phases connection in order RYB and also if any wrong connections want to see the order of 3 phases connections
please check this video
https://www.youtube.com/watch?v=N0FTCOjbftg&list=LL&index=1&t=28s
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.