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: mbed EasyCAT_lib
Revision 2:1e780f9c21b1, committed 2021-10-04
- Comitter:
- neeyoo
- Date:
- Mon Oct 04 15:16:46 2021 +0000
- Parent:
- 1:1e7996e6c4a7
- Commit message:
- for motion;
Changed in this revision
| EasyCAT_lib.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/EasyCAT_lib.lib Wed Jan 09 09:45:21 2019 +0000 +++ b/EasyCAT_lib.lib Mon Oct 04 15:16:46 2021 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/EasyCAT/code/EasyCAT_lib/#7816b38c99cc +https://os.mbed.com/users/neeyoo/code/EasyCAT_lib/#66867fae2256
--- a/main.cpp Wed Jan 09 09:45:21 2019 +0000
+++ b/main.cpp Mon Oct 04 15:16:46 2021 +0000
@@ -25,12 +25,12 @@
#include "mbed.h"
#include "EasyCAT.h" // EasyCAT library to interface the LAN9252
-
+
void Application (void);
-EasyCAT EASYCAT; // EasyCAT istantiation
+EasyCAT EASYCAT(DC_SYNC); // EasyCAT istantiation
// The constructor allow us to choose the pin used for the EasyCAT SPI chip select
// Without any parameter pin 9 will be used
@@ -55,37 +55,19 @@
-//---- pins declaration ------------------------------------------------------------------------------
-
-
-
-AnalogIn Ana0(A0); // analog input 0
-AnalogIn Ana1(A1); // analog input 1
-
-
-DigitalOut Out_0(A2); // four bits output
-DigitalOut Out_1(A3); //
-DigitalOut Out_2(A4); //
-DigitalOut Out_3(A5); //
-
-DigitalIn In_0(D3); // four bits input
-DigitalIn In_1(D5); //
-DigitalIn In_2(D6); //
-DigitalIn In_3(D7); //
-
-
+InterruptIn event(D2); // This pin receive the SM interrupt
+ // generated by the LAN9252
+
+
+void Campionatura(void);
//---- global variables ---------------------------------------------------------------------------
-
-
-UWORD ContaUp; // used for sawthoot test generation
-UWORD ContaDown; //
-
unsigned long Millis = 0;
-unsigned long PreviousSaw = 0;
unsigned long PreviousCycle = 0;
+int32_t data_test = 0;
+int32_t j = 0;
//---- declarations for Arduino "millis()" emulation -----------------------
@@ -112,8 +94,6 @@
InitMillis(); // init Arduino "millis()" emulation
- ContaDown.Word = 0x0000;
- ContaUp.Word = 0x0000;
//---- initialize the EasyCAT board -----
if (EASYCAT.Init() == true) // initialization
@@ -137,132 +117,59 @@
Led = 0; //
wait_ms(125); //
} //
- }
+ }
+
+
+ event.fall(&Campionatura);
- while (1) //---- main loop ---------------------------
+ while (1)
{
- // In the main loop we must call ciclically the
- // EasyCAT task and our application
- //
- // This allows the bidirectional exachange of the data
- // between the EtherCAT master and our application
- //
- // The EasyCAT cycle and the Master cycle are asynchronous
- //
-
- // wait_ms(20); // Here we to set the EasyCAT cycle time
- // according to the needs of our application
- //
- // For user interface applications a cycle time of 100mS,
- // or even more, is appropriate, but, for data processing
- // applications, a faster cycle time may be required
- //
- // In this case we can also completely eliminate this
- // delay in order to obtain the fastest possible response
-
-
- // Instead we can also use millis() to set the cycle time
- //
- // example:
- Millis = millis(); //
- if (Millis - PreviousCycle >= 10) // each 10 mS
- { //
- PreviousCycle = Millis; //
-
- EASYCAT.MainTask(); // execute the EasyCAT task
-
- Application(); // execute the user application
- }
+ // everything happens in interrupt
}
}
-
-//---- user application ------------------------------------------------------------------------------
-
-void Application (void)
-
-{
- float Analog;
- // --- analog inputs management ---
- //
- Analog = Ana0.read(); // read analog input 0
- Analog = Analog * 255; // normalize it on 8 bits
- EASYCAT.BufferIn.Byte[0] = (uint8_t)Analog; // and put the result into
- // input Byte 0
-
- Analog = Ana1.read(); // read analog input 1
- Analog = Analog * 255; // normalize it on 8 bits
- EASYCAT.BufferIn.Byte[1] = (uint8_t)Analog; // and put the result into
- // input Byte 1
-
-
- // --- four output bits management ----
- //
- if (EASYCAT.BufferOut.Byte[0] & 0b00000001) // the four output bits are mapped to the
- Out_0 = 1; // lower nibble of output Byte 0
- else //
- Out_0 = 0; //
- //
- if (EASYCAT.BufferOut.Byte[0] & (1<<0)) //
- Out_0 = 1; //
- else //
- Out_0 = 0; //
- //
- if (EASYCAT.BufferOut.Byte[0] & (1<<1)) //
- Out_1 = 1; //
- else //
- Out_1 = 0; //
- //
- if (EASYCAT.BufferOut.Byte[0] & (1<<2)) //
- Out_2 = 1; //
- else //
- Out_2 = 0; //
+//---- interrupt service --------------------------------------------------------------------------------
+
+ // The EasyCAT task and the User
+ // Application run in interrupt
//
- if (EASYCAT.BufferOut.Byte[0] & (1<<3)) //
- Out_3 = 1; //
- else //
- Out_3 = 0; //
-
- //--- four input bits management ---
+ // Take care that the EtherCAT task + User Application
+ // time is less that the master cycle time
+
+ void Campionatura() //
+ { //
+ EASYCAT.MainTask(); // EtherCAT task
//
- EASYCAT.BufferIn.Byte[6] = 0x00; // the four input pins are mapped to the
- if (!In_0) // lower nibble of input Byte 6
- EASYCAT.BufferIn.Byte[6] |= 0b00000001; //
- if (!In_1) //
- EASYCAT.BufferIn.Byte[6] |= 0b00000010; //
- if (!In_2) //
- EASYCAT.BufferIn.Byte[6] |= 0b00000100; //
- if (!In_3) //
- EASYCAT.BufferIn.Byte[6] |= 0b00001000; //
-
-
- // --- test sawtooth generation ---
- //
- Millis = millis(); // each 100 mS
-
- if (Millis - PreviousSaw >= 100) //
- { //
- PreviousSaw = Millis; //
- //
- ContaUp.Word++; // we increment the variable ContaUp
- ContaDown.Word--; // and decrement ContaDown
- } //
+ Application();
+ printf("%d \n", millis() - PreviousCycle);
+ PreviousCycle = millis(); // User application
+
+ }
+
+// User application
- // we use these variables to create sawtooth,
- // with different slopes and periods, for
- // test pourpose, in input Bytes 2,3,4,5,30,31
-
- EASYCAT.BufferIn.Byte[2] = ContaUp.Byte[0]; // slow rising slope
- EASYCAT.BufferIn.Byte[3] = ContaUp.Byte[1]; // extremly slow rising slope
-
- EASYCAT.BufferIn.Byte[4] = ContaDown.Byte[0]; // slow falling slope
- EASYCAT.BufferIn.Byte[5] = ContaDown.Byte[1]; // extremly slow falling slope
-
-
- EASYCAT.BufferIn.Byte[30] = ContaUp.Byte[0] << 2; // medium speed rising slope
- EASYCAT.BufferIn.Byte[31] = ContaDown.Byte[0] << 2; // medium speed falling slope
-}
+void Application (void)
+{
+ EASYCAT.BufferIn.Cust.centerXL = data_test;
+ EASYCAT.BufferIn.Cust.centerYL = data_test;
+ EASYCAT.BufferIn.Cust.forceL = data_test;
+ EASYCAT.BufferIn.Cust.yawL = data_test;
+ EASYCAT.BufferIn.Cust.pitchL = data_test;
+ EASYCAT.BufferIn.Cust.rollL = data_test;
+ EASYCAT.BufferIn.Cust.centerXR = data_test;
+ EASYCAT.BufferIn.Cust.centerYR = data_test;
+ EASYCAT.BufferIn.Cust.forceR = data_test;
+ EASYCAT.BufferIn.Cust.yawR = data_test;
+ EASYCAT.BufferIn.Cust.pitchR = data_test;
+ EASYCAT.BufferIn.Cust.rollR = data_test;
+ EASYCAT.BufferIn.Cust.yawH = data_test;
+ EASYCAT.BufferIn.Cust.pitchH = data_test;
+ EASYCAT.BufferIn.Cust.rollH = data_test;
+
+ data_test++;
+
+}
//--- functions for Arduino "millis()" emulation -------------------------------------
@@ -276,4 +183,4 @@
void mS_Tick(void)
{
MillisVal++;
-}
\ No newline at end of file
+}