Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of foc-ed_in_the_bot_compact by
Revision 4:a6669248ce4d, committed 2016-03-18
- Comitter:
- bwang
- Date:
- Fri Mar 18 12:07:14 2016 +0000
- Parent:
- 3:9b20da3f0055
- Child:
- 5:efd3838b79a6
- Child:
- 7:caebf421f288
- Child:
- 9:074575151e4b
- Commit message:
- moved commutation to current sampling routine
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Mar 18 10:52:45 2016 +0000
+++ b/main.cpp Fri Mar 18 12:07:14 2016 +0000
@@ -25,17 +25,21 @@
float last_d = 0.0f, last_q = 0.0f;
float d_ref = -0.0f, q_ref = -50.0f;
-void main_loop();
+void commutate();
void zero_current();
void config_globals();
void startup_msg();
extern "C" void TIM1_UP_TIM10_IRQHandler(void) {
if (TIM1->SR & TIM_SR_UIF ) {
+ toggle = 1;
+ ADC1->CR2 |= 0x40000000;
+ volatile int delay;
+ for (delay = 0; delay < 35; delay++);
+ toggle = 0;
adval1 = ADC1->DR;
adval2 = ADC2->DR;
- ADC1->CR2 |= 0x40000000;
- //while((ADC1->SR & ADC_SR_EOC) == 0 || (ADC2->SR & ADC_SR_EOC) == 0) {}
+ commutate();
}
TIM1->SR = 0x00;
}
@@ -137,15 +141,15 @@
pc.printf("\n\r");
}
-void main_loop() {
+void commutate() {
p = pos.GetElecPosition() - POS_OFFSET;
if (p < 0) p += 2 * PI;
float sin_p = sinf(p);
float cos_p = cosf(p);
- float pos_dac = 0.85f * p / (2 * PI) + 0.05f;
- DAC->DHR12R2 = (unsigned int) (pos_dac * 4096);
+ //float pos_dac = 0.85f * p / (2 * PI) + 0.05f;
+ //DAC->DHR12R2 = (unsigned int) (pos_dac * 4096);
ia = ((float) adval1 / 4096.0f * AVDD - I_OFFSET - ia_supp_offset) / I_SCALE;
ib = ((float) adval2 / 4096.0f * AVDD - I_OFFSET - ib_supp_offset) / I_SCALE;
@@ -179,9 +183,12 @@
if (vq < -1.0f) vq = -1.0f;
if (vq > 1.0f) vq = 1.0f;
- //DAC->DHR12R2 = (unsigned int) (-q * 20 + 2048);
+ DAC->DHR12R2 = (unsigned int) (-q * 20 + 2048);
//DAC->DHR12R2 = (unsigned int) (-vd * 2000 + 2048);
+ //vd = 0.0f;
+ //vq = -1.0f;
+
float valpha = vd * cos_p - vq * sin_p;
float vbeta = vd * sin_p + vq * cos_p;
@@ -198,9 +205,6 @@
config_globals();
startup_msg();
- Ticker loop;
- loop.attach_us(main_loop, 200);
-
for (;;) {
/*
q_ref = 0.0f;
