|
From: Xavier L. <Ba...@us...> - 2010-05-23 14:10:50
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "krobot".
The branch, master has been updated
via 804d30b9270027e496e3c21627314b14901e95f6 (commit)
from 583b99a782254c915c3d667ad6363ef3affb5407 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 804d30b9270027e496e3c21627314b14901e95f6
Author: Xavier Lagorce <Xav...@cr...>
Date: Sun May 23 16:10:06 2010 +0200
Added hysteretic comparators and event generation to the watch_adc module.
the main.c program has been update to reflect these changes
-----------------------------------------------------------------------
Changes:
diff --git a/elec/boards/MotherBoard_KrobotJr2010/Firmware/main.c b/elec/boards/MotherBoard_KrobotJr2010/Firmware/main.c
index 34d77fb..bbb1bec 100644
--- a/elec/boards/MotherBoard_KrobotJr2010/Firmware/main.c
+++ b/elec/boards/MotherBoard_KrobotJr2010/Firmware/main.c
@@ -167,6 +167,13 @@ static void TimerHandler(eventid_t id) {
}*/
}
+static void adcHandler(eventid_t id) {
+ palClearPad(IOPORT3, GPIOC_LED);
+}
+static void adcNHandler(eventid_t id) {
+ palSetPad(IOPORT3, GPIOC_LED);
+}
+
/*
* Entry point, note, the main() function is already a thread in the system
* on entry.
@@ -175,9 +182,11 @@ int main(int argc, char **argv) {
static const evhandler_t evhndl[] = {
TimerHandler,
+ adcHandler,
+ adcNHandler
};
static EvTimer evt;
- struct EventListener el0;
+ struct EventListener el0, elADC, elNADC;
(void)argc;
(void)argv;
@@ -228,6 +237,9 @@ int main(int argc, char **argv) {
evtInit(&evt, MS2ST(500)); /* Initializes an event timer object. */
evtStart(&evt); /* Starts the event timer. */
chEvtRegister(&evt.et_es, &el0, 0); /* Registers on the timer event source. */
+ chEvtRegister(&adcAlarmWarn[ADC_3], &elADC, 1);
+ chEvtRegister(&adcAlarmOK[ADC_3], &elNADC, 2);
+ adcSetAlarm(ADC_3, 1800, 2200);
while (TRUE)
chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
return 0;
diff --git a/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.c b/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.c
index 1946b3b..af02c0c 100644
--- a/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.c
+++ b/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.c
@@ -11,6 +11,10 @@
static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static Thread *adctp;
+static uint16_t compHigh[8] = {4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096};
+static uint16_t compLow[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+static uint8_t alarmActi[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+
const ADCConfig adccfg = {};
const ADCConversionGroup adcgrpcfg = {
TRUE,
@@ -31,11 +35,23 @@ const ADCConversionGroup adcgrpcfg = {
*/
static void adccallback(adcsample_t *buffer, size_t n) {
+ static uint8_t ind[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t i;
+
(void)n;
- if (buffer[ADC_3] >= 2000)
- palClearPad(IOPORT3, GPIOC_LED);
- else
- palSetPad(IOPORT3, GPIOC_LED);
+
+ for (i=0; i < 8; i++) {
+ if (alarmActi[i]) {
+ if (ind[i] == 0 && buffer[i] >= compHigh[i]) {
+ ind[i] = 1;
+ chEvtBroadcastI(&adcAlarmWarn[i]);
+ }
+ if (ind[i] == 1 && buffer[i] <= compLow[i]) {
+ ind[i] = 0;
+ chEvtBroadcastI(&adcAlarmOK[i]);
+ }
+ }
+ }
}
static WORKING_AREA(adc_continuous_wa, 256);
@@ -50,6 +66,8 @@ static msg_t adc_continuous_thread(void *p){
void adcWatchInit(void) {
+ uint8_t i;
+
// Init pins
palSetGroupMode(IOPORT1, PAL_PORT_BIT(4) | PAL_PORT_BIT(5), PAL_MODE_INPUT_ANALOG);
palSetGroupMode(IOPORT3, PAL_PORT_BIT(0) | PAL_PORT_BIT(1) | PAL_PORT_BIT(2)
@@ -58,7 +76,26 @@ void adcWatchInit(void) {
// Start ADC driver
adcStart(&ADCD1, &adccfg);
+ // Init trigger event
+ for (i=0; i < 8; i++) {
+ chEvtInit(&adcAlarmWarn[i]);
+ chEvtInit(&adcAlarmOK[i]);
+ }
+
// Start conversion Thread
adctp = chThdCreateStatic(adc_continuous_wa, sizeof(adc_continuous_wa),
NORMALPRIO + 9, adc_continuous_thread, NULL);
}
+
+void adcSetAlarm(uint8_t adc, uint16_t histLow, uint16_t histHigh) {
+
+ chSysLock();
+ compLow[adc] = histLow;
+ compHigh[adc] = histHigh;
+ alarmActi[adc] = 1;
+ chSysUnlock();
+}
+
+void adcResetAlarm(uint8_t adc) {
+ alarmActi[adc] = 0;
+}
diff --git a/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.h b/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.h
index 892cddb..650acc7 100644
--- a/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.h
+++ b/elec/boards/MotherBoard_KrobotJr2010/Firmware/watch_adc.h
@@ -19,6 +19,11 @@
#define ADC_6 6
#define ADC_7 7
+// Event sources
+EventSource adcAlarmWarn[8], adcAlarmOK[8];
+
void adcWatchInit(void);
+void adcSetAlarm(uint8_t adc, uint16_t histLow, uint16_t histHigh);
+void adcResetAlarm(uint8_t adc);
#endif
hooks/post-receive
--
krobot
|