potato

Dependencies:   mbed

Fork of analoghalls by N K

Committer:
nki
Date:
Mon Feb 16 20:16:01 2015 +0000
Revision:
0:9753f3c2e5ca
Child:
1:70eed554399b
hello bayley;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nki 0:9753f3c2e5ca 1 #include "isr.h"
nki 0:9753f3c2e5ca 2 #include "mbed.h"
nki 0:9753f3c2e5ca 3 #include "shared.h"
nki 0:9753f3c2e5ca 4 #include "constants.h"
nki 0:9753f3c2e5ca 5
nki 0:9753f3c2e5ca 6 /*
nki 0:9753f3c2e5ca 7 void commutate() {
nki 0:9753f3c2e5ca 8 if(BROCK_COMMUTATE){
nki 0:9753f3c2e5ca 9 motor->hall = (halla.read() << 2) + (hallb.read() << 1) + hallc.read();
nki 0:9753f3c2e5ca 10 if (motor->hall != HNext[motor->last_hall] && motor->last_hall != 0) {
nki 0:9753f3c2e5ca 11 motor->reverses++;
nki 0:9753f3c2e5ca 12 if (motor->reverses < 2) return;
nki 0:9753f3c2e5ca 13 }
nki 0:9753f3c2e5ca 14 motor->reverses = 0;
nki 0:9753f3c2e5ca 15 motor->last_hall = motor->hall;
nki 0:9753f3c2e5ca 16 motor->last_time = motor->ticks;
nki 0:9753f3c2e5ca 17 motor->major_pos = 60.0f * ATable[motor->hall];
nki 0:9753f3c2e5ca 18 motor->ticks = 0.0f;
nki 0:9753f3c2e5ca 19 }
nki 0:9753f3c2e5ca 20 else{
nki 0:9753f3c2e5ca 21
nki 0:9753f3c2e5ca 22 }
nki 0:9753f3c2e5ca 23 }
nki 0:9753f3c2e5ca 24 */
nki 0:9753f3c2e5ca 25
nki 0:9753f3c2e5ca 26
nki 0:9753f3c2e5ca 27
nki 0:9753f3c2e5ca 28 void dtc_update() {
nki 0:9753f3c2e5ca 29
nki 0:9753f3c2e5ca 30 float angle = motor->whangle;
nki 0:9753f3c2e5ca 31
nki 0:9753f3c2e5ca 32
nki 0:9753f3c2e5ca 33 float ia = angle - motor->sensor_phase;
nki 0:9753f3c2e5ca 34 if (ia < 0) ia += 360.0f;
nki 0:9753f3c2e5ca 35 if (ia >= 360.0f) ia -= 360.0f;
nki 0:9753f3c2e5ca 36 float ib = ia - 120.0f;
nki 0:9753f3c2e5ca 37 if (ib < 0) ib += 360.0f;
nki 0:9753f3c2e5ca 38 float ic = ia + 120.0f;
nki 0:9753f3c2e5ca 39 if (ic >= 360.0f) ic -= 360.0f;
nki 0:9753f3c2e5ca 40
nki 0:9753f3c2e5ca 41 motor->dtc_a = sinetab[(int) (ia)] * motor->throttle;
nki 0:9753f3c2e5ca 42 motor->dtc_b = sinetab[(int) (ib)] * motor->throttle;
nki 0:9753f3c2e5ca 43 motor->dtc_c = sinetab[(int) (ic)] * motor->throttle;
nki 0:9753f3c2e5ca 44
nki 0:9753f3c2e5ca 45 if (motor->halt) {
nki 0:9753f3c2e5ca 46 pha = 0.0f;
nki 0:9753f3c2e5ca 47 phb = 1.0f;
nki 0:9753f3c2e5ca 48 phc = 0.0f;
nki 0:9753f3c2e5ca 49 } else {
nki 0:9753f3c2e5ca 50 pha = DB_COEFF * motor->dtc_a + DB_OFFSET;
nki 0:9753f3c2e5ca 51 phb = DB_COEFF * (1.0f - motor->dtc_b) + DB_OFFSET;
nki 0:9753f3c2e5ca 52 phc = DB_COEFF * motor->dtc_c + DB_OFFSET;
nki 0:9753f3c2e5ca 53 }
nki 0:9753f3c2e5ca 54 }