Modified Motor Driver Firmware to include Flash + Thermal
Dependencies: FastPWM3 mbed-dev-STM-lean
Diff: Calibration/calibration.cpp
- Revision:
- 58:32e8927fe39f
- Parent:
- 55:c4c9fec8539c
- Child:
- 63:10604c39666f
--- a/Calibration/calibration.cpp Thu Nov 07 18:14:51 2019 +0000 +++ b/Calibration/calibration.cpp Tue Feb 04 14:19:58 2020 +0000 @@ -217,20 +217,25 @@ } int raw_offset = (raw_f[0] + raw_b[n-1])/2; //Insensitive to errors in this direction, so 2 points is plenty + printf("Raw offset: %d \n\r", raw_offset); printf("\n\r Encoder non-linearity compensation table\n\r"); printf(" Sample Number : Lookup Index : Lookup Value\n\r\n\r"); - for (int i = 0; i<n_lut; i++){ // build lookup table - int ind = (raw_offset>>7) + i; + for (int i = 0; i<n_lut; i++){ + // build lookup table + int ind = (raw_offset>>12) + i; // shifted by lut_shift to ensure index is from 0 to 128 + if(ind > (n_lut-1)){ ind -= n_lut; } lut[ind] = (int) ((error_filt[i*NPP] - mean)*(float)(ps->GetCPR())/(2.0f*PI)); + //int temp = (int) ((error_filt[i*NPP] - mean)*(float)(ps->GetCPR())/(2.0f*PI)); printf("%d %d %d \n\r", i, ind, lut[ind]); wait(.001); } ps->WriteLUT(lut); // write lookup table to position sensor object + //memcpy(controller->cogging, cogging_current, sizeof(controller->cogging)); //compensation doesn't actually work yet.... memcpy(&ENCODER_LUT, lut, 128*4); // copy the lookup table to the flash array