stock mbed AnalogReads current loop closed and working
Fork of priustroller by
Diff: context.cpp
- Revision:
- 30:2b6d426f3bfc
- Parent:
- 29:cb03760ba9ea
- Child:
- 31:86b87913d8e1
--- a/context.cpp Sat Mar 14 23:42:46 2015 +0000 +++ b/context.cpp Sun Mar 15 01:45:22 2015 +0000 @@ -88,9 +88,17 @@ } void Context::InitData() { + serial = new Serial(USBTX, USBRX); + serial->baud(115200); + serial->printf("%s\n\r", "Init Serial Communications"); + sense_p = new AnalogHallPositionSensor(_pos_a_pin, _pos_b_pin, _cal1_a, _cal2_a, _cal1_b, _cal2_b, _offset); channel_ib = NativeAnalogIn::PinToAdcChannel(_ib_pin); channel_ic = NativeAnalogIn::PinToAdcChannel(_ic_pin); + AnalogIn dummyb = AnalogIn(_ib_pin); + AnalogIn dummyc = AnalogIn(_ic_pin); + _dummyb = dummyb; + _dummyc = dummyc; throttle = new Throttle(_throttle_pin, _min, _max); sense_bus = new VoltageSensor(); sense_t_motor = new TempSensor(); @@ -107,10 +115,30 @@ filter_d = new MeanFilter(_filter_strength); filter_q = new MeanFilter(_filter_strength); + wait_us(100000); - serial = new Serial(USBTX, USBRX); - serial->baud(115200); - serial->printf("%s\n\r", "Init Serial Communications"); + float ib_mean, ic_mean; + TIM2->DIER = 0x0000; + for (int i = 0; i < 1000; i++) { + TIM2->SR &= ~1; + ADC1->SQR1 &= ~ADC_SQR1_L; + ADC1->SQR3 = 0; + ADC1->SQR3 |= channel_ib; + ADC1->CR2 |= ADC_CR2_SWSTART; + while ((ADC1->SR & 2) == 0){} + ib_mean += (float) ADC1->DR / 4095.0f; + + ADC1->SQR3 = 0; + ADC1->SQR3 |= channel_ic; + ADC1->CR2 |= ADC_CR2_SWSTART; + while ((ADC1->SR & 2) == 0){} + ic_mean += (float) ADC1->DR / 4095.0f; + } + TIM2->DIER = 0x0001; + ib_mean /= 1000.0f; + ic_mean /= 1000.0f; + + motor->InitSensors(ib_mean, ic_mean, _scale); debugger = new BufferedDebugger(this, _debugger_channels, _debugger_size); }