Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmiriuta committed Sep 20, 2020
1 parent 6d231f1 commit e565574
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* kalman filter *(voltage, current)*

**new:**
* DSHOT600
* DSHOT300
* autotiming *(current based)*
* bootloader *(betaflight 4way interface uploader)*
* 600K ERpm
* 48KHz, 24KHz
Expand Down
40 changes: 2 additions & 38 deletions src/main/drivers/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,30 +295,6 @@ void inputProshot() {
LED_ON(LED_GREEN);
#endif

// ToDo
// check 4us constant (1% data error, if CRC ok sound ?!?)
/*
uint32_t proshotWidth[3];
for (int i = 0; i < 3; i++) {
proshotWidth[i] = (inputDmaBuffer[i*2 + 2] - inputDmaBuffer[i*2]);
if ((proshotWidth[i] >= ((INPUT_PROSHOT1000_LO_WIDTH_MIN + INPUT_PROSHOT1000_HI_WIDTH_MIN) / (INPUT_PROSHOT1000_PRESCALER + 1))) &&
(proshotWidth[i] <= ((INPUT_PROSHOT1000_LO_WIDTH_MAX + INPUT_PROSHOT1000_HI_WIDTH_MAX) / (INPUT_PROSHOT1000_PRESCALER + 1)))) {
// proshot signal valid (hi + lo = 4us)
} else {
input.DataValid = false;
input.DataErrorCounter++;
__enable_irq();
#if (defined(_DEBUG_) && defined(DEBUG_INPUT_PROSHOT1000))
LED_OFF(LED_GREEN);
#endif
return;
}
}*/

for (int i = 0; i < 4; i++) {
pulseValue[i] = ((inputDmaBuffer[i*2 + 1] - inputDmaBuffer[i*2]) - 45) / 6;
}
Expand Down Expand Up @@ -369,29 +345,17 @@ void inputDshot() {

for (int i = 0; i < 32; i+=2) {
uint32_t tmp = (inputDmaBuffer[i + 1] - inputDmaBuffer[i]);
if (( tmp > 44) && (tmp < 69)) {
if (( tmp > INPUT_DSHOT_HI_WIDTH_MIN) && (tmp < INPUT_DSHOT_HI_WIDTH_MAX)) {
pulseValue[i >> 1] = 1;
}
// ToDo
// no plausibility check (if CRC ok sound ?!?)
/*
if (((inputDmaBuffer[(i << 1) + 1] - inputDmaBuffer[i << 1]) > 17) && ((inputDmaBuffer[(i << 1) + 1] - inputDmaBuffer[i << 1]) < 40)) {
pulseValue[i] = 0;
} else {
if (((inputDmaBuffer[(i << 1) + 1] - inputDmaBuffer[i << 1]) > 45) && ((inputDmaBuffer[(i << 1) + 1] - inputDmaBuffer[i << 1]) < 68)) {
pulseValue[i] = 1;
} else {
input.DataErrorCounter++;
}
}*/
}

calculatedCRC = ( (pulseValue[0] ^ pulseValue[4] ^ pulseValue[8]) << 3 | (pulseValue[1] ^ pulseValue[5] ^ pulseValue[9]) << 2 |
(pulseValue[2] ^ pulseValue[6] ^ pulseValue[10]) << 1 | (pulseValue[3] ^ pulseValue[7] ^ pulseValue[11]));

receivedCRC = (pulseValue[12] << 3 | pulseValue[13] << 2 | pulseValue[14] << 1 | pulseValue[15]);

if(calculatedCRC == receivedCRC) {
if((calculatedCRC == receivedCRC) && (data >= INPUT_VALUE_MIN) && (data <= INPUT_VALUE_MAX)) {
data = (pulseValue[0] << 10 | pulseValue[1] << 9 | pulseValue[2] << 8 | pulseValue[3] << 7 | pulseValue[4] << 6 |
pulseValue[5] << 5 | pulseValue[6] << 4 | pulseValue[7] << 3 | pulseValue[8] << 2 | pulseValue[9] << 1 | pulseValue[10]);

Expand Down
8 changes: 6 additions & 2 deletions src/main/drivers/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define INPUT_DMA_BUFFER_SIZE_PWM 3
#define INPUT_DMA_BUFFER_SIZE_MAX 32

// AUTODETECT
#define INPUT_AUTODETECT_PRESCALER 5

// PROSHOT1000 (MIN, MAX +-10%)
Expand All @@ -20,6 +21,10 @@
#define INPUT_PROSHOT1000_LO_WIDTH_MIN 131
#define INPUT_PROSHOT1000_LO_WIDTH_MAX 161

// DSHOT
#define INPUT_DSHOT_HI_WIDTH_MIN 44
#define INPUT_DSHOT_HI_WIDTH_MAX 69

// DSHOT600 (MIN, MAX +-10%)
#define INPUT_DSHOT600_PRESCALER 0
#define INPUT_DSHOT600_HI_WIDTH_MIN 25
Expand All @@ -38,11 +43,10 @@
#define INPUT_PWM_PRESCALER 96
#define INPUT_SERVOPWM_WIDTH_MIN 43297
#define INPUT_SERVOPWM_WIDTH_MAX 52918

#define INPUT_SERVOPWM_WIDTH_MIN_US 491
#define INPUT_SERVOPWM_WIDTH_MAX_US 983


// input/output
#define INPUT_VALUE_MIN 0
#define INPUT_VALUE_MAX 2047
#define INPUT_NORMED_MIN 0
Expand Down

0 comments on commit e565574

Please sign in to comment.