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: RPCInterface mbed-dsp mbed
Diff: main.cpp
- Revision:
- 0:5e49c3bc05f5
- Child:
- 1:eabd95ed3f53
diff -r 000000000000 -r 5e49c3bc05f5 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed May 11 16:58:41 2016 +0000
@@ -0,0 +1,133 @@
+#include "mbed.h"
+#include "SerialRPCInterface.h"
+#include "L6470.h"
+#include "HC595.h"
+
+// Global objects
+DigitalOut led_red(LED_RED); // active low to turn on red part of RGB LED on FRDM-K22F
+DigitalOut led_green(LED_GREEN); // active low to turn on green part of RGB LED on FRDM-K22F
+DigitalOut led_blue(LED_BLUE); // active low to turn on blue part of RGB LED on FRDM-K22F
+
+SerialRPCInterface rpc(USBTX, USBRX, 115200); // create serial rpc interface on usb virtual com port
+L6470 motor(PTD6, PTD7, PTD5, PTD4); // create motor object with mosi, miso, sclk, cs on FRDM-K22F
+
+HC595 hc595(PTC5, PTC10, PTC7); // create led bar driver with ser, oe, rclk, and srclk
+AnalogIn lightSense(PTB0); // analog voltage from light sensor on PDU
+PwmOut brightness(PTA5); // brightness of PDU
+DigitalIn sw0(PTC9);
+DigitalIn sw1(PTC8);
+DigitalIn sw2(PTA12);
+DigitalIn sw3(PTA13);
+
+float ledbar = 1;
+
+// RPC Function calls
+void GetStatus(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ int temp = motor.GetStatus();
+ output->putData(temp & 0xFFFFFF);
+};
+
+void GetABSPOS(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ // uint32_t temp = motor.GetParameter(ABS_POS);
+ int temp = motor.GetParameter(ABS_POS);
+ temp = (temp & 0x3FFFFF); // mask 22 bit value
+ output->putData(temp);
+};
+
+// motor.move(direction, step)
+void Move(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ int arg0 = input->getArg<int>();
+ int arg1 = input->getArg<int>();
+ motor.Move(arg0, arg1);
+};
+
+void Run(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ int arg0 = input->getArg<int>();
+ motor.Run(arg0);
+};
+void Stop(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ motor.HardStop();
+};
+
+void ResetPosition(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ motor.ResetPosition();
+};
+
+void SetParameter(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ // uint8_t arg0 = input->getArg<int>();
+ // uint32_t arg1 = input->getArg<int>();
+ int arg0 = input->getArg<int>();
+ int arg1 = input->getArg<int>();
+ motor.SetParameter(arg0, arg1);
+};
+
+void SetLEDBar(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ int arg0 = input->getArg<int>();
+ hc595.bar(arg0);
+ //output->putData(arg0);
+}
+
+void GetParameter(Arguments *input, Reply *output)
+{
+ led_green = !led_green;
+ //uint8_t arg0 = input->getArg<int>();
+ //uint32_t temp = motor.GetParameter(arg0);
+ int arg0 = input->getArg<int>();
+ int temp = motor.GetParameter(arg0);
+ output->putData(temp);
+}
+
+// RPC variable and function assignments
+RPCFunction rpc_GetStatus(&GetStatus, "GetStatus");
+RPCFunction rpc_GetABSPOS(&GetABSPOS, "GetABSPOS");
+RPCFunction rpc_Move(&Move, "Move");
+RPCFunction rpc_Run(&Run, "Run");
+RPCFunction rpc_Stop(&Stop, "Stop");
+RPCFunction rpc_ResetPosition(&ResetPosition, "ResetPosition");
+RPCFunction rpc_SetParameter(&SetParameter, "SetParameter");
+RPCFunction rpc_GetParameter(&GetParameter, "GetParameter");
+RPCFunction rpc_SetLEDBar(&SetLEDBar, "SetLEDBar");
+
+int main(){
+ // Turn off LED's
+ led_red = 1; led_green = 1; led_blue = 1;
+
+ // set motor parameters
+ motor.Reset();
+ motor.HardStop();
+ motor.SetParameter(ACC, 0xFF);
+ motor.SetParameter(DEC, 0xFF);
+ motor.SetParameter(MAX_SPEED, 0x17);
+ motor.SetParameter(MIN_SPEED, 0x00);
+ motor.SetParameter(KVAL_HOLD, 0x29);
+ motor.SetParameter(KVAL_RUN, 0x29);
+ motor.SetParameter(KVAL_ACC, 0x29);
+ motor.SetParameter(KVAL_DEC, 0x29);
+
+ motor.SetParameter(STALL_TH, 0x30);
+
+ while(1){
+ if (sw0)
+ led_red = 0;
+ else
+ led_red = 1;
+
+ wait_ms(500);
+ }
+}