;----------------------------------------------------------;
; 83kHz Position capture and servo operation interrupt
background:
push T0L
pushw Z
in T0L, SREG ;Save flags
mov ZL, _PvEnc ;ZL[1:0] = previous A/B signal
in _PvEnc, PIND ;Sample A/B signal into _PvEnc[1:0]
swap _PvEnc ;/
ldi ZH, 1 ;Convert it to sequencial number.
sbrc _PvEnc, 1 ;
eor _PvEnc, ZH ;/
sub ZL, _PvEnc ;Decode motion
andi ZL, 3 ;/
breq enc_zr ;-> Not moved
cpi ZL, 3 ;
breq enc_rev ;-> -1 count
cpi ZL, 1 ;
breq enc_fwd ;-> +1 count
mov ZL, _PvDir ;-> Missing code recovery:
mov ZH, _PvDir ; double count for previous direction
lsl ZL ;
asr ZH ;/
rjmp enc_add
enc_rev:ldiw Z, -1
rjmp PC+3
enc_fwd:ldiw Z, 1
mov _PvDir, ZL
enc_add:addw _Pos, Z
adc _PosX, ZH
enc_zr:
dec _CtDiv ;Decrement 1/83 divider
rjne bgnd_exit ;If not overflow, exit interrupt routine.
em chưa check code, nhưng khả năng là encoder có 4 trạng thái cho 1 chu kì, ta có thể bắt xung ở trạng thái thứ 1 và thứ 4 = +4 > tương đương bắt được xung gấp 2 lần tần số quét
Lần sửa cuối bởi nhatson, ngày 07-03-2015 lúc 08:22:36 AM.
À, nhắc mới nhớ, xin hỏi các cao thủ luôn:
1. Mấy chú Tây làm bằng cách nào mà có thể cắt nhôm sắt hộp chính xác ta? Độ chính xác là bao nhiêu? Mình có thể DIY được ko?
2. Cắt dây & cắt tia nước thì ưu nhược điểm ra sao?
Lần sửa cuối bởi Gamo, ngày 07-03-2015 lúc 08:30:46 AM.
@nhatson
Cái source của elm-chan thì có xem qua, nhưng là ASM, mà môn này thì gà quá nên vẫn không hiểu. Tất cả các phát triển từ nguồn elm-chan đều dùng ASM. Phải chi dùng C hay gì đó thì hay biết mấy.
Ngoài ra nó còn có cascade pid nữa. Nói chung không chuyên nên khó xơi hehe.
@cuong
Nếu ứng dụng của bạn chỉ dùng để chỉnh cữ, giữ phôi.. trong cưa tự động thì không quá khó.
DT: O7837277II - CKD's Youtube Channel - Facebook - Tổng hợp chủ đề
17 ds 3, Thạnh Mỹ Lợi, Q2, tp.HCM
Ủa, cắt dây có phải cắt EDM ko? Hay là cắt bằng dây kim cương?
Lần sửa cuối bởi Gamo, ngày 07-03-2015 lúc 05:14:23 PM.
Hehe, tại đang tính đi cắt dây/water jet. Thế rồi lại té ngửa ra là có 2 pp cắt dây lận
cảm ơn bác linh và các CKD, em bị chứng ì tâm lý huhu,hihi. Làm cho step chạy rồi thì đấu ac driver vô chân tương tự như đấu vô step driver thôi đúng không các bác?hihihi.
em mới vừa lòi ra câu hỏi. trong đoạn chương trình này:
// Define a stepper and the pins it will use
AccelStepper stepper(AccelStepper:RIVER, 13, 12); // 13-PUL,12-DIR
void setup()
{
stepper.setAcceleration(8000);
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(1000);
}
long current_position;
void loop()
{
current_position = stepper.currentPosition();
if(current_position>=50000){
stepper.moveTo(0);
}
if(current_position<=0){
stepper.moveTo(-500);
}
stepper.run();
}
đoạn nào tính tỉ số xung và vòng quay vậy các bác, để cần biết mô tơ quay chính xác một vòng cần bao nhieu xung. ttrên step em cài :400 fulse/rev, full curent
Em mới tham gia lớp học arduino dành cho trẻ em và các cụ ông.
Em muốn đọc nội dung từ file text, từng dòng từng dòng, mà đọc mãi chẳng thấy hàm nào readln cả. Em thuộc nhóm cao tuổi, lười nghĩ mẹo nên lên đây hỏi trước.
Cụ CKD giúp với, em làm mẹo cũng được, nhưng dự là sẽ test ra được 1 đống lỗi (em đang làm QA :-s)
Chưa thử nhưng với cái ex từ arduino.cc thì nó đọc từ từ.
https://www.arduino.cc/en/Tutorial/ReadWriteMã:/* SD card read/write This example shows how to read and write data to and from an SD card file The circuit: * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 4 created Nov 2010 by David A. Mellis modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. */ #include <SPI.h> #include <SD.h> File myFile; void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("Initializing SD card..."); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. myFile = SD.open("test.txt", FILE_WRITE); // if the file opened okay, write to it: if (myFile) { Serial.print("Writing to test.txt..."); myFile.println("testing 1, 2, 3."); // close the file: myFile.close(); Serial.println("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } // re-open the file for reading: myFile = SD.open("test.txt"); if (myFile) { Serial.println("test.txt:"); // read from the file until there's nothing else in it: while (myFile.available()) { Serial.write(myFile.read()); } // close the file: myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } } void loop() { // nothing happens after setup }
Chưa làm qua, nhung có 2 giả thuyết.Mã:while (myFile.available()) { Serial.write(myFile.read()); }
1. Mỗi lần nó đọc 1 byte. Vậy muốn biết nó hết 1 dòng chưa thì phải dò ký tự return.
2. Nếu mỗi lần nó đọc 1 dòng thì quá tuyệt rồi.
DT: O7837277II - CKD's Youtube Channel - Facebook - Tổng hợp chủ đề
17 ds 3, Thạnh Mỹ Lợi, Q2, tp.HCM
myFile.read() nó đọc cả file mới đau.
Lệnh
myFfile.read() là nó đọc từng byte (char) một.
Vậy muốn nó đọc hết một dòng mới thôi thì có thể đọc kiểu này.
Mã:char thisByte; String str = ""; while (myFile.available()) { thisByte = myFile.read(); if (thisByte != 10) 'kiểm tra nếu thấy char 10 (line feed) thì ngừng { str =str + thisByte; } else { Serial.print("New line: "); Serial.println(str); str = ""; } }
DT: O7837277II - CKD's Youtube Channel - Facebook - Tổng hợp chủ đề
17 ds 3, Thạnh Mỹ Lợi, Q2, tp.HCM