Bayley Wang
/
analoghalls
potato
Fork of analoghalls by
isr.cpp
- Committer:
- nki
- Date:
- 2015-02-16
- Revision:
- 0:9753f3c2e5ca
- Child:
- 1:70eed554399b
File content as of revision 0:9753f3c2e5ca:
#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; } }