#define info0 "EMP4 Build-01 ZDRV " #define info1 "F/W Z0325-P01_v0.15 " #define info2 "Assy: CES180325-3 " #define info3 "Date: 09/21/2018 " /* * Z0325-C01_v0.15 9/21/18 -------------------------------- * Ready for Acceptance Test * Pending LCD Display I2C Address update * Pending Zscale Calibration * Program 74%, Memory 55% * Copy from Z0325-C01_v0.15 9/19/18 * -------------------------------------------------------- * LCD 2004 I2C (5V) * A5 = SCL * A4 = SDA * -------------------------------------------------------- * Pro MiniPORT Assignments * A7 Z.Speed Zclk Setting * A6 * A5/D19 I2C-SCL * A4/D18 I2C-SDA * ----------------------- * A3/D17 PReady Input PWMGen.D12 Interface (LO=NotReady) * A2/D16 ESense Input (End Sense) * A1/D15 BSense Input (Bottom Sense) * A0/D14 TSense Input (Top Sense) * D13 Output Zdir ZDRV-DIR (IDE Reserved Output Only) * D12 Output Zclk ZDRV-CLK * D11 Output Zen ZDRV-EN * D10 Output EDM-ON * D9 Input Key Zdn * D8 Input Key Zup * D7 Input Key Zrun * D6 Input Key Zset * D5 Input Key Page * D4 Output RUNspeed * D3 Input ISense * D2 Input PSense * ----------------------- * D1 RXD System Reserved * D0 TXD System Reserved * * === Pro Mini w/ 5x1 Extended Header ========================= * (D9)(D8)(D7)(D6)(D5)(D4)(D3)(D2)(GND)(RES)(RXD)(TXD) < DTR > * (GND) * < RX > * A4 * < TX > * A5 * < VCC > * A6 * < CTS > * A7 * < GND > * (D10)(D11)(D12)(D13)(A0)(A1)(A2)(A3)(VCC)(RES)(GND)(RAW) * * === TB6560 Stepper Driver =================================== * A+ (Red) * A- (Blue) * B+ (Green) * B- (Black) * Note: New Z Axal B+/B- Swapped * * === TB6560 SW Settings ====================================== * --- Running Current --- (1.5A*) * sw1 OFF OFF OFF OFF OFF ON OFF ON* ON ON ON ON ON ON * sw2 OFF OFF ON ON ON OFF ON OFF* OFF ON OFF ON ON ON * sw3 ON ON OFF OFF ON OFF ON ON* OFF OFF ON ON OFF ON * S1 ON OFF ON OFF ON ON OFF ON* OFF ON OFF ON OFF OFF * 0.3 0.5 0.8 1 1.1 1.2 1.4 1.5* 1.6 1.9 2 2.2 2.6 3.0 * --- Stop Current --- (50%) * S2 OFF* ON * 50%* 20% * --- Excitation Mode --- (Mode 16) * S3 OFF ON ON* OFF (CPU Controls Pin, OFF=HiRES to Commom+5V ,Set to OFF ) * S4 OFF OFF ON* ON (Set to ON for CPU Controls) * 1 2 8* 16 * CPU Controls S3, S4=ON Default, FAST=ON(8) HiRES=OFF(16) <-- Use This One * CPU Controls S3, S4=OFF Default, FAST=OFF(1) HiRES=OFF(2) * CPU Controls S4, S3=ON Default, FAST=OFF(2) HiRES=ON(8) * CPU Controls S4, S3=OFF Default, FAST=OFF(1) HiRES=ON(16) * --- Decay Setting --- * S5 OFF* OFF ON ON * S6 OFF* ON OFF ON * 0%* 25% 50% 100% * ZScale per Inch Excitation Mode Note: * Tested on Z60mm * Mode.1 3off 4off = Not Used * Mode.2 3on 4off = Normal = 2546 (0.0003928) * Mode.8 3on 4on = fine = 10172 (0.0000983) as Fast * Mode.16 3off 4on = Ultra = 20318 (0.0000492) as HiRES * --- Program Settings --- * Default S3=OFF S4=ON * TB6560 GND = SystemGND * D4=S3- LO=(S3=ON)FAST HI=(S3=OFF)HiRES * ============================================================= */ // LCD 2004A with I2C #include #include #include // the pins on the I2C chip used for LCD connections: // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol //LiquidCrystal_I2C lcd2(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 2004A LCD LiquidCrystal_I2C lcd2(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // 2004A LCD // Z-drive Stepper Output Port #define Zclk 12 //ZDRV Clock output #define ZclkH HIGH #define ZclkL LOW #define Zdir 13 //ZDRV Direction output #define ZdirUP HIGH #define ZdirDN LOW #define Zen 11 //ZDRV Enable output #define Zon LOW #define Zoff HIGH #define EDM 10 //EDM Enable output #define EDMon HIGH #define EDMoff LOW // Sense Input Port #define TSense 14 //TOP Limit #define BSense 15 //BOT Limit #define ESense 16 //End Detect #define PSense 2 //Probe input #define ISense 3 //Probe Current // PWMGen Interface #define PWMGen 17 //PWMGen Interface Input Port #define NotReady LOW // Z-Drive working variable long Zcount; //Current Step Count (from Work Zero) long ZcountSet; //Target Step Count (from Work Zero) long ZcountSave; //+UP -DN Temp Display Counts (from Work Zero) long ZcountEnd; //Finish Depth (from Work Zero) long ZcountPark; //Part in Counts (from Work Zero) long ZcountProx; //Prox in Counts (from Work Zero) long ZcountGap; //Gap in Counts (from Work Zero) long ZcountMax; //Top Limit Counts (from Work Zero) long ZcountMin; //Bottom Limit Counts (from Work Zero) long ZcountZero; //Z Machine Work Zero offset long ZcountMMax; //Z Machine Top Limit TSense long ZcountMMin; //Z Machine Bot Limit BSense (BOT = Machine-Zero) long ZcountCHK; // Z Temp storage for Error Checking // Z-Drive from Work Zero float ZmaxDefault = 2.1; //Z Top 2.1 Inch (60mm Axis) - Justify Sensing Block Thk. float Zmax = 2.1; // Z Top in Inch float Zmin = 0; // Machine Zero Default = 0 float Zprox = 0.05; //Prox Zone in Inch from Zero float Zend = -0.1; //Job Finish Depth in Inch from Zero (initial value) float Zgap = 0.02; //Max gap prior Prox Clearing in Inch from Zero float Zzero; // Zero in Inch #define Zcalblock 1.0 //CAL Prode DIA or Thickness 1-inch default // Z-Drive Default Value //Mode.8 3on 4on = fine = 10160 (0.0000983) as FAST //Mode.16 3off 4on = Ultra = 20320 (0.0000491) as HiRES long Zscale; //steps counts per Inch long Zscalefast = 10160; //steps counts per Inch (TB6560 Mode8 S3=ON S4=ON) 60mm FAST long Zscalehires = 20320; //steps counts per Inch (TB6560 Mode16 S3=OFF S4=ON) 60mm HiRES // Z-drive speed control #define Zs3sw 4 //Z S3 Speed Select port #define Zfast LOW //S3=ON #define Zhires HIGH //S3=OFF // Z-Drive Operating Range Limits #define ZscaleMin 800 //counts #define ZscaleMax 30000 //counts // Z-Drive Pulse 10KHz=100uS 20KHz=50uS #define A7pulse A7 //POT Speed Adj #define pulseMin 35 //Maximum Speed, Minimum ON-Time in uS #define A7comp 16 //estimated CPU Execution compansation in uS long Ain7; //Read A7 Input 0-255 for WORK Zclk // System control Keys #define kdn 9 //Z Down Key #define kup 8 //Z up Key #define krun 7 //Z Run Key #define kset 6 //Z stop Key #define kpage 5 //Z Page key // Processing Steps Index byte Stest; //Test/Monitor process steps byte Srng; //Range Finder process steps byte Scal; //Calibration process steps byte Sset; //Setup process steps byte Srun; //Run process steps byte Sinf; //INF process steps byte Zclear; //Test if Not Clear Discharging Gap byte Zstop; // 0=RUN // Z Progress Msg place in Program Segment #include const char string_0[] PROGMEM = "[RUN] key to Start"; const char string_1[] PROGMEM = "[S]Change [R]Next "; const char string_2[] PROGMEM = "[S]Select [R]Start"; const char string_3[] PROGMEM = "JOB Finished. "; const char string_4[] PROGMEM = "to Start Position "; const char string_5[] PROGMEM = "Job in Progress..."; const char string_6[] PROGMEM = "PAUSE [RUN]resume "; const char string_7[] PROGMEM = "Job Cancel [R]next"; const char string_8[] PROGMEM = "Z-Bottom Reached. "; const char string_9[] PROGMEM = "Cleaning... "; const char string_10[] PROGMEM = "goto TOP Position "; const char string_11[] PROGMEM = "goto BOT Position "; const char string_12[] PROGMEM = "goto MID Position "; const char string_13[] PROGMEM = "Range Setup DONE "; const char string_14[] PROGMEM = "[S]Save [RUN]Skip "; const char string_15[] PROGMEM = "New Value Saved "; const char string_16[] PROGMEM = "No Change, Skip "; const char string_17[] PROGMEM = "seek DN Base Ref0 "; const char string_18[] PROGMEM = "seek DN 1-inch BLK"; const char string_19[] PROGMEM = "Calibration DONE "; const char string_20[] PROGMEM = "Detect Work ZERO "; const char string_21[] PROGMEM = "SysCheck NotReady!"; const char string_22[] PROGMEM = "[S]Cancel [R]Next "; // Z Progress Msg strings define const char* const Zprogress[] PROGMEM = { string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9, string_10, string_11, string_12, string_13, string_14, string_15, string_16, string_17, string_18, string_19, string_20, string_21, string_22 }; char buffer[22]; // make sure this is large enough for the largest string it must hold // Z-drive RUN Mode byte Zedm; // 0=FAST, 1=HiRES, 3=AUTO #define mFAST 0 #define mHiRES 1 #define mAUTO 2 char* Zedmmsg[]={ //6-chr " FAST ", //0 No Read-Out, Finish at ESense, BSense " HiRES", //1 W/ Readout, Finish at ESense, BSense " AUTO "}; //2 // Zpage Page MSG 2004 20 chr byte Zpage = 0; //default #define firstpage 0 #define RUN 0 //=ok= #define INF 1 //=ok= #define TEST 2 //=ok= #define RNG 3 //=ok= #define CAL 4 //=ok= #define lastpage 4 char* Zpagemsg[]={ //6-chr " ", //0 "INFO> ", //1 "TEST> ", //2 "RANGE ", //3 " "}; //4 // Zmode Status Line MSG 2004 20 chr byte Zmode = 0; //Mode state #define mUP 1 #define mDN 2 #define mPause 3 #define mError 4 char* Zmodemsg[]={ // 8-chr " ------ ", //0 " (z.UP) ", //1 Zdir " (z.DN) ", //2 Zdir " PAUSE! ", //3 Zstop=1 " ERROR! ", //4 ? " << >> "}; //5 Srun=2 // System I/O & Variable #define disptime 2000 //delay for Display in mS #define keydebounce 250 //delay for keydebounce #define holdindex 30 //Key refresh count before switch to high speed byte pagemsg; //Init Display MSG once String mfg; //Long MSG String mfgtemp; //Long MSG temp unsigned long msNow; //Current Wait Timer unsigned long msLast; //Last Wait Timer unsigned long msWait = 1000; //default 1-second Wait float Zdata; //common shares data int kupHold; //UP long press int kdnHold; //DN long press int keyHold; //any long press byte AltDisp; //Alternate Display Toggle Flag /* ------------------------------------------------------------------------*/ /// Setup Start Here void setup() { //Stepper Drive Controls Output pinMode(EDM,OUTPUT); digitalWrite(EDM,EDMoff); pinMode(Zen,OUTPUT); digitalWrite(Zen,Zoff); pinMode(Zdir,OUTPUT); digitalWrite(Zdir,ZdirUP); pinMode(Zclk,OUTPUT); digitalWrite(Zclk,ZclkL); pinMode(Zs3sw,OUTPUT); digitalWrite(Zs3sw,Zfast); //ZDRV Sensing input pinMode(TSense,INPUT_PULLUP); pinMode(BSense,INPUT_PULLUP); pinMode(ESense,INPUT_PULLUP); pinMode(PSense,INPUT_PULLUP); pinMode(ISense,INPUT_PULLUP); // Key Input pinMode(kdn,INPUT_PULLUP); pinMode(kup,INPUT_PULLUP); pinMode(krun,INPUT_PULLUP); pinMode(kset,INPUT_PULLUP); pinMode(kpage,INPUT_PULLUP); // PWMGen Interface Input pinMode(PWMGen,INPUT_PULLUP); // Load Z Setup Default Zdefault(); // Update Z Data Zupdate(); // Enable Z-Driver digitalWrite(Zen,Zon); //LCD setup lcd2.begin(20, 4); // Display Info mfg = (info0); printmfg(0,0); mfg = (info1); printmfg(0,1); mfg = (info2); printmfg(0,2); mfg = (info3); printmfg(0,3); delay(disptime*2); // StartUp Page Zpage = RUN; } /// Setup End Here /* ------------------------------------------------------------------------*/