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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
* Pulse Width Modulation(パルス幅変調)制御 [#eb3dc03c]
 
* モータードライバ: TA8428K [#d0431e69]
- http://akizukidenshi.com/download/ta8428k(s).pdf
 
|*#|*Name    |*Arg    |*Func         |
|*1|##IN1  ##|##i1 ##|制御用入力端子|
|*2|##IN2  ##|##i2 ##|^             |
|*3|##OUTA ##|##o1 ##|〜1.5A        |
|*4|##GND  ##|##gnd##|GND           |
|*5|##OUTA~##|##o2 ##|              |
|*6|##---- ##|##-- ##|              |
|*7|##Vcc  ##|##vcc##|VCC〜30V      |
 
|     |    |lx: |     |lx:   |c
|*Mode|*IN1|*IN2|*OUTA|*OUTA~|
|*制動| H  | H  | L   |  L   |
|*正転| H  | L  | H   |  L   |
|*逆転| L  | H  | L   |  H   |
|*停止| L  | L  | Z   |  Z   |
 
|C[10  uF]|水色106|
|C[ 0.1uF]|水色104|
 
* ハード [#j705136e]
### verilog
;pin ctrl.gnd = driver.gnd = 0V
;pin ctrl.vcc = 5V
;pin driver.vcc = 12V
 
;C[10  uF](driver.gnd, driver.vcc)
;C[ 0.1uF](driver.gnd, driver.vcc)
 
;Arduino ctrl
;TA8428K driver
 
;driver.i1 = ctrl.D3
;driver.i2 = ctrl.D11
 
;pin driver.o1;
;pin driver.o2;
###
 
* ソフト [#f78cb14d]
### C
void setup() {
  Serial.begin(9600);
  pinMode( 3, OUTPUT);
  pinMode(11, OUTPUT);
}
 
int c1 =  3;
int c2 = 11;
int t = 100;
int d =  50;
int command = 0;
void loop() {
 
  if (Serial.available() > 0) {
    command = Serial.read();
  }
 
  digitalWrite(c1, LOW )
  digitalWrite(c2, HIGH)
  delay(d);
 
  digitalWrite(c1, LOW)
  digitalWrite(c2, LOW)
  delay(t-d);
}
###
 
*** ディーゼル [#x2389d6e]
###
int iAna0 =  0;
int pPwm1 =  3;
int pPwm2 = 11;
 
int base = 0;
 
#define avelg 2
#define avesz (1<<avelg)
int avebf[avesz];
int avelc=0;
int ave=0;
 
int Ave(int value) {
  ave -= avebf[avelc];    avebf[avelc] = value >> avelg;
  ave += avebf[avelc];
 
  avelc++;
  if (avelc == avesz) avelc = 0;
 
  return ave;
}
 
void setPwvWidth0311(int r) {
  TCCR2B &= B11111000;
  switch(r) {
    case    1:  TCCR2B |= B00000001;  break;
    case    8:  TCCR2B |= B00000010;  break;
    case   32:  TCCR2B |= B00000011;  break;
    default  : 
    case   64:  TCCR2B |= B00000100;  break;
    case  128:  TCCR2B |= B00000101;  break;
    case  256:  TCCR2B |= B00000110;  break;
    case 1024:  TCCR2B |= B00000111;  break;
  }
}
 
void setup() {
  Serial.begin(9600);
  
  setPwvWidth0311(1024);
 
  pinMode(pPwm1, OUTPUT);
  pinMode(pPwm2, OUTPUT);
  
  pinMode( 8, OUTPUT);
  pinMode( 9,  INPUT);
  pinMode(10, OUTPUT);
  
  analogWrite(pPwm1, 0 );
  analogWrite(pPwm2, 0 );
  
  digitalWrite( 8,  LOW);
  digitalWrite(10, HIGH);
 
  base = analogRead(iAna0)+10;
  Serial.print("base == ");
  Serial.println(base);
  
  for(int i = 0; i<avesz; i++) {
    avebf[i] = 0;
  }
}
 
void loop() {
  int sw    = digitalRead(9);
  int value = analogRead(iAna0);
  int ave = Ave(value);
  int acc   = 0;
  
  
  if (sw == LOW) {
    acc = (1024-ave)/4;
  }
  else {
    acc = (ave - base)/2;
    if (acc <  5) acc =   0;
    if (acc >254) acc = 254;
  }
  if (1) {
    Serial.print(value);
    Serial.print("\t");
    Serial.print(ave);
    Serial.print("\t");
    Serial.println(acc);
  }
  
  analogWrite(pPwm1, 0 );
  analogWrite(pPwm2, acc);
  delay(100);
}
###
 
*** [#g8acfab8]
###
int iAna0 =  1;
int iAna1 =  2;
int pPwm1 =  5;
int pPwm2 =  6;
int pLed1 =  3;
int pLed2 =  9;
 
int base0 = 0;
int base1 = 0;
 
#define avelg 2
#define avesz (1<<avelg)
int avebf[2][avesz];
int avelc[2] = {0,0};
int ave[2] = {0,0};
 
int Ave(int id, int value) {
  if (id > 2) return 0;
  ave[id] -= avebf[id][avelc[id]];    avebf[id][avelc[id]] = value >> avelg;
  ave[id] += avebf[id][avelc[id]];
 
  avelc[id]++;
  if (avelc[id] == avesz) avelc[id] = 0;
 
  return ave[id];
}
 
const int vBaseOffset = 10;
void setup() {
  Serial.begin(9600);
 
  pinMode(pPwm1, OUTPUT);
  pinMode(pPwm2, OUTPUT);
  pinMode(pLed1, OUTPUT);
  pinMode(pLed2, OUTPUT);
 
  analogWrite(pPwm1, 0);
  analogWrite(pPwm2, 0);
 
  base0 = analogRead(iAna0) + vBaseOffset;
  base1 = analogRead(iAna1) + vBaseOffset;
  Serial.print("base == ");
  Serial.print(base0);
  Serial.print(", ");
  Serial.println(base1);
 
  for (int i = 0; i < avesz; i++) {
    avebf[0][i] = 0;
    avebf[1][i] = 0;
  }
}
 
int gSwtchingLock = false;
int gDir = 0;
void loop() {
  int value0 = analogRead(iAna0);
  int value1 = analogRead(iAna1);
  int ave0 = Ave(0, value0);
  int ave1 = Ave(1, value1);
  
 
  int acc = (int)((ave0 - base0) * 0.7);
  if (acc <   5) acc =   0;
  if (acc > 254) acc = 254;
 
  bool sw = (ave1 - base1) > base1;
  if (gSwtchingLock == false && sw == true && acc == 0) {
    gDir = 1 - gDir;
    gSwtchingLock = true;
  }
  
  if (gSwtchingLock == true)
  {
    Serial.print((gDir == 0) ? "200\t100\t" : "100\t200\t");
    Serial.println(gDir);
    if (sw == false) gSwtchingLock = false;
    return;
  }
 
  if (gSwtchingLock) {
    analogWrite(pPwm1, 0);
    analogWrite(pPwm2, 0);
    delay(10);
    return;
  }
 
  if (true) {
    Serial.print(ave0);
    Serial.print("\t");
    Serial.print(ave1);
    Serial.print("\t");
    Serial.println(acc);
  }
 
  if (gDir == 1) {
    analogWrite(pPwm1, 0 );
    analogWrite(pPwm2, acc);
    analogWrite(pLed1, 0 );
    analogWrite(pLed2, acc);
  }
  else {
    analogWrite(pPwm1, acc);
    analogWrite(pPwm2, 0);
    analogWrite(pLed1, acc);
    analogWrite(pLed2, 0);
  }
  delay(100);
}
###
    技術 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS