-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPWM_Control.HEX.ino
137 lines (105 loc) · 3.51 KB
/
PWM_Control.HEX.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Three - Phase - Motor - Control
// Author: Arshia Keshvari
// POWER ENGINEERING
// Duty cycle = (TON/(TON + TOFF)) *100
// Pin allocation and configuration
byte A = 0; // Phase A
byte B = 1; // Phase B
byte C = 2; // Phase C
byte OnOffCtrl = 3; // Shutdown control of the motor LOW or HIGH states
byte OffSw = 4; // Stop or Start Switch LOW or HIGH states
byte DirectionSw = 5; // Clockwise or anti-clockwise switch LOW or HIGH states
byte manualbrake = 6; // Slowly slows down the motor until it reaches zero
int potentiometer = 15; // 10k ohm variable resistor manually controlled by user
// Declaring Values/Paramaeteres to be calculated
float input_frequency = 0; // input frequency determined by potentiometer value
float t = 0; // Time delay
int potValue; // int variable to later on store the value fo the pot
// Runs at the start of the program
void setup () {
pinMode(A,OUTPUT); // Phase A
pinMode(B,OUTPUT); // Phase B
pinMode(C,OUTPUT); // Phase C
pinMode(OnOffCtrl,OUTPUT); // On/Off Control Output to IGBTS to turn on/off motor
pinMode(potentiometer,INPUT); // Potentiometer input
pinMode(OffSw,INPUT); // On/Off Control Input using a switch
pinMode(DirectionSw,INPUT); // Direction Switch Input using a switch.
pinMode(manualbrake,INPUT); // Manual brake button
}
// Shuts down the signals A, B ,and C
void ShutDown_All_Signals(){
digitalWrite(A, LOW);
digitalWrite(B, LOW);
digitalWrite(C, LOW);
}
void Turn_On_Signals_clockwise (){
digitalWrite(A, HIGH);
delay(t);
digitalWrite(B, LOW);
delay(t);
digitalWrite(C, HIGH);
delay(t);
digitalWrite(A, LOW);
delay(t);
digitalWrite(B, HIGH);
delay(t);
digitalWrite(C, LOW);
delay(t);
}
void Turn_On_Signals_anti_clockwise(){
digitalWrite(C, HIGH);
delay(t);
digitalWrite(B, LOW);
delay(t);
digitalWrite(A, HIGH);
delay(t);
digitalWrite(C, LOW);
delay(t);
digitalWrite(B, HIGH);
delay(t);
digitalWrite(A, LOW);
delay(t);
}
// Direction proccess of the motor or crane
void Direction_Proccess(){
if (digitalRead(DirectionSw)){
Turn_On_Signals_clockwise();
}
else{
Turn_On_Signals_anti_clockwise();
}
}
void loop() {
potValue = analogRead(potentiometer);
input_frequency = map(potValue, 0, 1023, 0, 50);
t = 1000/(input_frequency*6);
// In case speed control dosent work uncomment this to perform debugging
// lcd.setCursor(0,0);
// lcd.print(input_frequency);
// lcd.setCursor(0,1);
// lcd.print(t);
// lcd.setCursor(0,2);
// lcd.print(potValue);
// delayMicroseconds(1);
// Implement the on functionality code
if (digitalRead(OffSw) == LOW){
digitalWrite(OnOffCtrl, LOW);
Direction_Proccess();
}
else if (digitalRead(OffSw) == HIGH){
digitalWrite(OnOffCtrl, HIGH);
ShutDown_All_Signals();
}
brake();
}
// Brake function
void brake(){
while(digitalRead(manualbrake)){
digitalWrite(OnOffCtrl,HIGH); // Shutdown logic state
ShutDown_All_Signals();
}
while(digitalRead(OffSw)){
digitalWrite(OnOffCtrl,HIGH);
ShutDown_All_Signals();
}
}