Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftPWM USBDevice mbed
Diff: main.cpp
- Revision:
- 2:31a9ee6d066d
- Parent:
- 1:2c0e9ef138a4
- Child:
- 3:7a2b052c95a3
diff -r 2c0e9ef138a4 -r 31a9ee6d066d main.cpp
--- a/main.cpp Fri Apr 17 03:14:39 2015 +0000
+++ b/main.cpp Fri Apr 17 04:46:12 2015 +0000
@@ -1,5 +1,5 @@
#include "mbed.h"
-#include "USBSerial.h"
+//#include "USBSerial.h"
#include "SoftPWM.h"
AnalogIn Y_Axis(P0_13);
@@ -10,7 +10,10 @@
SoftPWM Y_PWM(P0_10); //P0_10
SoftPWM Z_PWM(P0_4); //P0_4
-USBSerial serial;
+//USBSerial serial;
+
+Serial Send_Stage_Controller(P0_19,NC);
+//Serial Receive_Stage_Controller(NC,P0_18); //NULL-MOdem
#define MAX_LOGIC 10000 // Full-deflection Max Range
#define MIN_LOGIC 0 // Full-deflection Min Range
@@ -30,15 +33,17 @@
uint16_t Y_Speed = 4;
uint16_t Z_Speed = 4;
-bool X_Direction = FWD;
-bool Y_Direction = FWD;
-bool Z_Direction = FWD;
+char X_Direction = FWD;
+char Y_Direction = FWD;
+char Z_Direction = FWD;
uint16_t tempX_Speed = 1;
uint16_t tempY_Speed = 1;
uint16_t tempZ_Speed = 1;
-
+char Direction_Byte = 0x00; //This byte contains all the info about directions. USed for transfer to Stage Controller
+
+
main()
{
while(1)
@@ -59,9 +64,51 @@
if (Z_Speed < 2) {Z_Direction = REV;}
- serial.printf(" X_Direction : %u", X_Direction);
- serial.printf(" Y_Direction : %u \n",Y_Direction);
- serial.printf(" Z_Direction : %u \n",Z_Direction);
+
+ /*
+ Assemble the Direction byte for ransmission over Serial to Stage Controller. X_Dir bit 2 Y_Dir bit 1, and Z_Dir bit 0
+ */
+
+
+ Direction_Byte = Direction_Byte >> 3; //Clear 3 previous LSBits
+ Direction_Byte = (Direction_Byte | X_Direction) << 1; //Place X_Dir value and shift right: X_Dir is now bit 1
+ Direction_Byte = (Direction_Byte | Y_Direction) << 1; //Place X_Dir value and shift right: Y_Dir is now bit 1, X_Dir is now bit 2
+ Direction_Byte = (Direction_Byte | Z_Direction); //Place X_Dir value : Z_Dir is now bit 0, Y_Dir is now bit 1, X_Dir is now bit 2
+
+ Send_Stage_Controller.putc(Direction_Byte);
+
+
+ /*
+ //============================================================================
+ //At the receiver side the Direction_Byte will will be decoded as follows:
+
+ char Mask_X = 0x04;
+ char Mask_Y = 0x02;
+ char Mask_Z = 0x01;
+
+ char Manual_Direction_Received = Receive_Stage_Controller.getc();
+
+ char X_Dir_Received = (Manual_Direction_Received & Mask_X) >> 2;
+ char Y_Dir_Received = (Manual_Direction_Received & Mask_Y) >> 1;
+ char Z_Dir_Received = Manual_Direction_Received & Mask_Z;
+ */
+
+
+ /*
+ //=======================Only For Testing via NULL-Modem========================
+
+ wait(1);
+ serial.printf("X_Direction : %u\n",X_Dir_Received);
+ serial.printf("Y_Direction : %u\n",Y_Dir_Received);
+ serial.printf("Z_Direction : %u\n",Z_Dir_Received);
+
+ */
+ //=============================================================================
+
+
+ //serial.printf(" X_Direction : %u", X_Direction);
+ //serial.printf(" Y_Direction : %u \n",Y_Direction);
+ //serial.printf(" Z_Direction : %u \n",Z_Direction);
if(tempX_Speed != X_Speed)
{
@@ -69,7 +116,7 @@
X_PWM.period(Period_Array[X_Speed]);
X_PWM.write(0.5);
- serial.printf(" X_Period : %4.4f \n",Period_Array[X_Speed]);
+ //serial.printf(" X_Period : %4.4f \n",Period_Array[X_Speed]);
}
if(tempY_Speed != Y_Speed)
@@ -77,7 +124,7 @@
tempY_Speed = Y_Speed;
Y_PWM.period(Period_Array[Y_Speed]);
Y_PWM.write(0.5);
- serial.printf(" Y_Period : %4.4f \n",Period_Array[Y_Speed]);
+ //serial.printf(" Y_Period : %4.4f \n",Period_Array[Y_Speed]);
}
if(tempZ_Speed != Z_Speed)
@@ -85,7 +132,7 @@
tempZ_Speed = Z_Speed;
Z_PWM.period(Period_Array[Z_Speed]);
Z_PWM.write(0.5);
- serial.printf(" Z_Period : %4.4f \n",Period_Array[Z_Speed]);
+ //serial.printf(" Z_Period : %4.4f \n",Period_Array[Z_Speed]);
}
}
}