my test code 2

Dependencies:   mbed-dev-f303 FastPWM3

Files at this revision

API Documentation at this revision

Comitter:
monkey61
Date:
Fri Sep 24 02:06:16 2021 +0000
Parent:
58:4f8f58ecb52a
Commit message:
my test code

Changed in this revision

DRV8323/DRV.cpp Show annotated file Show diff for this revision Revisions of this file
DRV8323/DRV.h 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/DRV8323/DRV.cpp	Wed Sep 22 09:30:48 2021 +0000
+++ b/DRV8323/DRV.cpp	Fri Sep 24 02:06:16 2021 +0000
@@ -75,14 +75,15 @@
     spi_write(val);
         }
 
-
 CANMessage   txMsg_liu;
-void DRV832x::print_faults(CAN *_can)
+void DRV832x::print_faults(CAN *_can,ObserverStruct *obs)
 {
     uint16_t val1 = read_FSR1();
     wait_us(10);
     uint16_t val2 = read_FSR2();
     wait_us(10);
+    int16_t temp16;
+    static uint8_t count = 0;
     
     if(val1 & (1<<10)){printf("\n\rFAULT\n\r");}
 
@@ -109,14 +110,20 @@
     if(val2 & (1<<1)){printf("VGS_HC\n\r");}
     if(val2 & (1)){printf("VGS_LC\n\r");}
     
-    if(val1 >0 || val2>0)
+    if(val1 >0 || val2>0 || count>10)
     {
-        txMsg_liu.id = 10;
+        count = 0;
+        txMsg_liu.id = CAN_ID+9;
         txMsg_liu.data[0] = (val1>>8)&0xff;
         txMsg_liu.data[1] = (val1)&0xff;
         txMsg_liu.data[2] = (val2>>8)&0xff;
         txMsg_liu.data[3] = (val2)&0xff;
-        txMsg_liu.len = 4;
+        //send temp
+        temp16 = (int16_t)(obs->temperature*10);
+        txMsg_liu.data[4] = (temp16>>8)&0xff;
+        txMsg_liu.data[5] = (temp16)&0xff;
+        
+        txMsg_liu.len = 6;
         _can->write(txMsg_liu);
         
     
--- a/DRV8323/DRV.h	Wed Sep 22 09:30:48 2021 +0000
+++ b/DRV8323/DRV.h	Fri Sep 24 02:06:16 2021 +0000
@@ -1,6 +1,9 @@
 #ifndef DRV_H
 #define DRV_H
 
+#include "../structs.h"
+
+
 /// Registers ///
 #define FSR1            0x0     /// Fault Status Register 1
 #define FSR2            0x1     /// Fault Status Register 2
@@ -163,7 +166,7 @@
         void enable_gd(void);
         void disable_gd(void);
         void calibrate(void);
-        void print_faults(CAN *_can);
+        void DRV832x::print_faults(CAN *_can,ObserverStruct *obs);
         
     private:
         SPI *_spi;
--- a/main.cpp	Wed Sep 22 09:30:48 2021 +0000
+++ b/main.cpp	Fri Sep 24 02:06:16 2021 +0000
@@ -542,9 +542,14 @@
     pc.attach(&serial_interrupt);                                               // attach serial interrupt
 
 
-    
+    int counter = 0;
     while(1) {
-        drv.print_faults(&can);
+        drv.print_faults(&can,&observer);
+        //if(counter++>=10)
+//        {
+//            counter = 0;
+//            printf("Temp:%.1f\n\r" , observer.temperature);
+//        }
         wait(.1);
         //printf("%.3f  %.3f\n\r" , observer.temperature, observer.q_in);
         if(controller.otw_flag){gpio.led->write(!gpio.led->read());}