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
Revision 0:138f9a31cd1b, committed 2020-02-15
- Comitter:
- KardTwei
- Date:
- Sat Feb 15 22:25:18 2020 +0000
- Commit message:
- Initial commit, should be complete
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/canIds.h Sat Feb 15 22:25:18 2020 +0000 @@ -0,0 +1,41 @@ +// BPS +#define BPS_TRIP 0x002 +#define BPS_ALL_CLEAR 0x101 +#define BPS_OFF 0x102 +#define CURRENT_DATA 0x103 +#define VOLTAGE_DATA 0x104 +#define TEMPERATURE_DATA 0x105 +#define SOC_DATA 0x106 +#define WDOG_TRIGGERED 0x107 +#define CAN_ERROR 0x108 +#define BPS_COMMAND_MSG 0x109 + +// Motor +#define DC_BUS_CURRENT 0x600 +#define DC_BUS_VOLTAGE 0x601 +#define PHASE_B_CURRENT 0x602 +#define PHASE_C_CURRENT 0x603 +#define VEHICLE_VELOCITY 0x604 +#define MOTOR_VELOCITY 0x605 +#define VD 0x606 +#define VQ 0x607 +#define ID 0x608 +#define IQ 0x609 +#define BEMFD 0x60A +#define BEMFQ 0x60B +#define HEAT_SINK_TEMPERATURE 0x60C +#define MOTOR_TEMPERATURE 0x60D +#define DC_BUS_AMP_HOURS 0x60E +#define ODOMETER 0x60F + +// MPPT +#define MPPT_BASE_R 0x710 // MPPT Base ID (Request) +#define MPPT_BASE_A 0x770 // MPPT Base ID (Answer) +#define MPPT_OFF 0xF //MPPT Offset ID (set by DIP switch on board) + +// Array Temperature +// WARNING: TEMPORARY IDS +#define ARRAY_TEMP_1 0x798 +#define ARRAY_TEMP_2 0x799 + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Feb 15 22:25:18 2020 +0000
@@ -0,0 +1,85 @@
+#include "mbed.h"
+#include "canIds.h"
+#include "CAN.h"
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdio.h>
+
+//Pin definitions
+AnalogIn RTD0(A0); //Analog lines from RTD sensors
+AnalogIn RTD1(A1);
+AnalogIn RTD2(A2);
+AnalogIn RTD3(A3);
+AnalogIn RTD4(A4);
+AnalogIn RTD5(A5);
+AnalogIn RTD6(A6);
+AnalogIn RTD7(A7);
+
+CAN can(D10, D2); //D10 is Rx, D2 is Tx
+Serial pc(USBTX, USBRX);
+int maxTemp;
+
+int convertADC(AnalogIn RTD){
+ float temperature;
+ float floatRTD = (float)RTD;
+ float maxTemp = 200; //Temporary for now, Matthew will ask Hallock about later
+ temperature = (floatRTD*maxTemp)/4096;
+
+ return temperature;
+}
+
+int main() {
+
+ const int RTD_ID = 0x620;
+
+ float RTD0temp;
+ float RTD1temp;
+ float RTD2temp;
+ float RTD3temp;
+ float RTD4temp;
+ float RTD5temp;
+ float RTD6temp;
+ float RTD7temp;
+
+ while(1){
+
+ RTD0temp = convertADC(RTD0);
+ RTD1temp = convertADC(RTD1);
+ RTD2temp = convertADC(RTD2);
+ RTD3temp = convertADC(RTD3);
+ RTD4temp = convertADC(RTD4);
+ RTD5temp = convertADC(RTD5);
+ RTD6temp = convertADC(RTD6);
+ RTD7temp = convertADC(RTD7);
+
+ can.write(CANMessage(RTD_ID, (char*)(&RTD0temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD1temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD2temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD3temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD4temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD5temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD6temp),12));
+ can.write(CANMessage(RTD_ID, (char*)(&RTD7temp),12));
+
+ pc.printf("RTD0: %f\n", RTD0temp);
+ pc.printf("RTD1: %f\n", RTD0temp);
+ pc.printf("RTD2: %f\n", RTD0temp);
+ pc.printf("RTD3: %f\n", RTD0temp);
+ pc.printf("RTD4: %f\n", RTD0temp);
+ pc.printf("RTD5: %f\n", RTD0temp);
+ pc.printf("RTD6: %f\n", RTD0temp);
+ pc.printf("RTD7: %f\n", RTD0temp);
+
+ wait(.5);
+
+ //A7-A0 = RTD
+ //Send message of 7 every half second
+ //can.write should send message w/o having to worry
+ //Message ID, data (char buffer), length of char buffer
+ //ID for Can Bus, (8 byte index of RTD)(rest of data floating point), length of char buffer
+
+ //can.write(CANMessage(msgId, data, len))
+ //Max 5 V tolerance, 0-3.3 V read
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Feb 15 22:25:18 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file