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 analoghalls by
Diff: util.cpp
- Revision:
- 2:b5c19d4eddcc
- Parent:
- 1:70eed554399b
- Child:
- 3:86ccde39f61b
--- a/util.cpp Sat Feb 21 21:39:33 2015 +0000
+++ b/util.cpp Mon Feb 23 19:42:50 2015 +0000
@@ -4,16 +4,48 @@
#include <stdlib.h>
void initTimers() {
+#ifdef __USE_THROTTLE
dtc_upd_ticker.attach_us(&dtc_update, 200);
throttle_upd_ticker.attach_us(&throttle_update, 100000);
-
- pha.period_us(200);
- phb.period_us(200);
- phc.period_us(200);
+#endif
+
+#ifndef __NATIVE
+ pha.period_us(100);
+ phb.period_us(100);
+ phc.period_us(100);
pha = 0;
phb = 1.0f;
phc = 0;
+#endif
+ TIM2->CR1 &= ~(TIM_CR1_CEN);
+ TIM2->CR1 |= TIM_CR1_CMS;
+
+#ifdef __NATIVE
+ TIM2->CCMR1 |= TIM_CCMR1_OC1M_2;
+ TIM2->CCMR1 |= TIM_CCMR1_OC1M_1;
+ TIM2->CCMR1 |= TIM_CCMR1_OC2M_2;
+ TIM2->CCMR1 |= TIM_CCMR1_OC2M_1;
+ TIM2->CCMR2 |= TIM_CCMR2_OC3M_2;
+ TIM2->CCMR2 |= TIM_CCMR2_OC3M_1;
+
+ TIM2->CCER &= ~TIM_CCER_CC1P;
+ TIM2->CCER &= ~TIM_CCER_CC2P;
+ TIM2->CCER &= ~TIM_CCER_CC3P;
+
+ TIM2->CCER |= TIM_CCER_CC1E;
+ TIM2->CCER |= TIM_CCER_CC2E;
+ TIM2->CCER |= TIM_CCER_CC3E;
+
+ TIM2->PSC = 0;
+
+ TIM2->ARR = 10000;
+ TIM2->CCR1 = 0;
+ TIM2->CCR2 = 0;
+ TIM2->CCR3 = 0;
+#endif
+
+ TIM2->CR1 |= TIM_CR1_CEN;
}
void initPins() {
@@ -23,9 +55,10 @@
void initData() {
motor = (Motor*) malloc(sizeof(Motor));
motor->sensor_phase = SENSOR_PHASE;
- motor->halt = 1;
- motor->angle =0;
+ motor->halt = 0;
+ motor->angle = 0;
+#ifdef __USE_THROTTLE
float throttle_raw;
do {
throttle_raw = throttle;
@@ -39,4 +72,31 @@
} else {
motor->halt = 0;
}
+#else
+ motor->throttle = 1.0f;
+#endif
+}
+
+void setDtcA(float f) {
+#ifdef __NATIVE
+ TIM2->CCR3 = (uint16_t) (f * 10000.0f);
+#else
+ pha = f;
+#endif
+}
+
+void setDtcB(float f) {
+#ifdef __NATIVE
+ TIM2->CCR1 = (uint16_t) (f * 10000.0f);
+#else
+ phb = f;
+#endif
+}
+
+void setDtcC(float f) {
+#ifdef __NATIVE
+ TIM2->CCR2 = (uint16_t) (f * 10000.0f);
+#else
+ phc = f;
+#endif
}
\ No newline at end of file
