Bayley Wang
/
analoghalls
potato
Fork of analoghalls by
Diff: isr.cpp
- Revision:
- 0:9753f3c2e5ca
- Child:
- 1:70eed554399b
diff -r 000000000000 -r 9753f3c2e5ca isr.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/isr.cpp Mon Feb 16 20:16:01 2015 +0000 @@ -0,0 +1,54 @@ +#include "isr.h" +#include "mbed.h" +#include "shared.h" +#include "constants.h" + +/* +void commutate() { + if(BROCK_COMMUTATE){ + motor->hall = (halla.read() << 2) + (hallb.read() << 1) + hallc.read(); + if (motor->hall != HNext[motor->last_hall] && motor->last_hall != 0) { + motor->reverses++; + if (motor->reverses < 2) return; + } + motor->reverses = 0; + motor->last_hall = motor->hall; + motor->last_time = motor->ticks; + motor->major_pos = 60.0f * ATable[motor->hall]; + motor->ticks = 0.0f; + } + else{ + + } +} +*/ + + + +void dtc_update() { + + float angle = motor->whangle; + + + float ia = angle - motor->sensor_phase; + if (ia < 0) ia += 360.0f; + if (ia >= 360.0f) ia -= 360.0f; + float ib = ia - 120.0f; + if (ib < 0) ib += 360.0f; + float ic = ia + 120.0f; + if (ic >= 360.0f) ic -= 360.0f; + + motor->dtc_a = sinetab[(int) (ia)] * motor->throttle; + motor->dtc_b = sinetab[(int) (ib)] * motor->throttle; + motor->dtc_c = sinetab[(int) (ic)] * motor->throttle; + + if (motor->halt) { + pha = 0.0f; + phb = 1.0f; + phc = 0.0f; + } else { + pha = DB_COEFF * motor->dtc_a + DB_OFFSET; + phb = DB_COEFF * (1.0f - motor->dtc_b) + DB_OFFSET; + phc = DB_COEFF * motor->dtc_c + DB_OFFSET; + } +} \ No newline at end of file