diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-07 13:33:42 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-07 13:33:42 +0000 |
commit | d2e3d96b8d5305c9e74a762b22abe403dd726ec2 (patch) | |
tree | e6c0996517699031b5aa80a58ad3617b3b2db7e1 /testhal/SPC563Mxx | |
parent | 1d6fc52f437be05281f46ceb25d084a786a4d9a2 (diff) | |
download | ChibiOS-d2e3d96b8d5305c9e74a762b22abe403dd726ec2.tar.gz ChibiOS-d2e3d96b8d5305c9e74a762b22abe403dd726ec2.tar.bz2 ChibiOS-d2e3d96b8d5305c9e74a762b22abe403dd726ec2.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5375 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/SPC563Mxx')
-rw-r--r-- | testhal/SPC563Mxx/ADC/main.c | 206 |
1 files changed, 192 insertions, 14 deletions
diff --git a/testhal/SPC563Mxx/ADC/main.c b/testhal/SPC563Mxx/ADC/main.c index 846eb8f07..33389cba4 100644 --- a/testhal/SPC563Mxx/ADC/main.c +++ b/testhal/SPC563Mxx/ADC/main.c @@ -21,19 +21,21 @@ #include "ch.h"
#include "hal.h"
-#define ADC_GRP1_NUM_CHANNELS 2
+#define ADC_GRP1_NUM_CHANNELS 5
#define ADC_GRP1_BUF_DEPTH 8
-#define ADC_GRP2_NUM_CHANNELS 8
-#define ADC_GRP2_BUF_DEPTH 16
+//#define ADC_GRP2_NUM_CHANNELS 8
+//#define ADC_GRP2_BUF_DEPTH 16
+
+static ADCConfig adccfg1 = {0, 0};
static adcsample_t samples1[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
-static adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH];
+//static adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH];
/*
* ADC streaming callback.
*/
-size_t nx = 0, ny = 0;
+/*size_t nx = 0, ny = 0;
static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
(void)adcp;
@@ -43,24 +45,200 @@ static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) { else {
ny += n;
}
-}
+}*/
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
(void)adcp;
(void)err;
+
+ palSetPad(PORT11, P11_LED4);
+ chSysHalt();
}
/*
* ADC conversion group.
- * Mode: Linear buffer, 8 samples of 2 channels, SW triggered.
- * Channels: IN7, IN8.
+ * Mode: Linear buffer, 8 samples of 5 channels, SW triggered.
+ * Channels: ADC_CHN_VRL, ADC_CHN_VREF25, ADC_CHN_VREF50,
+ * ADC_CHN_VREF75, ADC_CHN_VRH.
+ *
+ * NOTE: The configuration of a sequence is very complex in this ADC
+ * implementation. Configurations are meant to be generated by the
+ * SPC5 Studio visual configuration tool and not be written manually.
+ * Writing complex sequences manually requires ad deep knowledge of both
+ * the EQADC peripheral and the driver implementation.
*/
+static const adccommand_t adcgrpcfg1_commands[ADC_GRP1_NUM_CHANNELS *
+ ADC_GRP1_BUF_DEPTH] = {
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRL),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF25),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF50),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VREF75),
+
+ EQADC_CONV_BN_ADC0 | EQADC_CONV_LST_64 | EQADC_CONV_CAL |
+ EQADC_CONV_FMT_RJU | EQADC_CONV_CONFIG_STD | EQADC_CONV_MSG_RFIFO(0) |
+ EQADC_CONV_CHANNEL(ADC_CHN_VRH)
+};
+
static const ADCConversionGroup adcgrpcfg1 = {
FALSE,
ADC_GRP1_NUM_CHANNELS,
NULL,
- adcerrorcallback
+ adcerrorcallback,
+ EQADC_CFCR_SSE | EQADC_CFCR_MODE_SWSS,
+ ADC_GRP1_BUF_DEPTH,
+ adcgrpcfg1_commands
};
/*
@@ -68,12 +246,12 @@ static const ADCConversionGroup adcgrpcfg1 = { * Mode: Continuous, 16 samples of 8 channels, SW triggered.
* Channels: IN7, IN8, IN7, IN8, IN7, IN8, Sensor, VBat/2.
*/
-static const ADCConversionGroup adcgrpcfg2 = {
+/*static const ADCConversionGroup adcgrpcfg2 = {
TRUE,
ADC_GRP2_NUM_CHANNELS,
adccallback,
adcerrorcallback,
-};
+};*/
/*
* Red LEDs blinker thread, times are in milliseconds.
@@ -121,7 +299,7 @@ int main(void) { /*
* Activates the ADC1 driver and the temperature sensor.
*/
- adcStart(&ADCD1, NULL);
+ adcStart(&ADCD1, &adccfg1);
/*
* Linear conversion.
@@ -132,14 +310,14 @@ int main(void) { /*
* Starts an ADC continuous conversion.
*/
- adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
+// adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
if (palReadPad(PORT11, P11_BUTTON1)) {
- adcStopConversion(&ADCD1);
+// adcStopConversion(&ADCD1);
}
chThdSleepMilliseconds(500);
}
|