summaryrefslogtreecommitdiff
path: root/openpicc/application/adc.c
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-13 04:37:38 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-13 04:37:38 +0000
commitee1f021427f8966fb29e70eab1a3be4345af65b1 (patch)
treeda67b9d102daaea09e06be52cc53c186a17ed507 /openpicc/application/adc.c
parent3d0a9bd40be2d014e0877eb623042c899d8cbe66 (diff)
Get tc_cdiv working (presumably, need to check on the oscilloscope)
Add adc code to read the field strength git-svn-id: https://svn.openpcd.org:2342/trunk@325 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
Diffstat (limited to 'openpicc/application/adc.c')
-rw-r--r--openpicc/application/adc.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/openpicc/application/adc.c b/openpicc/application/adc.c
new file mode 100644
index 0000000..4aa900e
--- /dev/null
+++ b/openpicc/application/adc.c
@@ -0,0 +1,45 @@
+/* AT91 ADC for OpenPICC
+ * (C) 2007 Henryk Plötz <henryk@ploetzli.ch>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+
+#include "openpicc.h"
+#include "board.h"
+
+#include <sys/types.h>
+#include <lib_AT91SAM7.h>
+
+static AT91S_ADC* adc = AT91C_BASE_ADC;
+
+int adc_get_field_strength(void)
+{
+ adc->ADC_CR = AT91C_ADC_START;
+ while( (adc->ADC_SR & AT91C_ADC_EOC4)==0) ;
+ return adc->ADC_CDR4;
+}
+
+void adc_init(void)
+{
+ // PRESCAL = 4 -> ADC clock = MCLK / 10 = 4.8 MHz (max is 5 MHz at 10 bit)
+ // Start time <20 us -> STARTUP=11
+ // Track and hold time >600 ns -> SHTIM=2
+ adc->ADC_MR = AT91C_ADC_TRGEN_DIS | AT91C_ADC_LOWRES_10_BIT |
+ AT91C_ADC_SLEEP_MODE | (4 << 8) | (11 << 16) | (2 << 24);
+ adc->ADC_IDR = 0xfffff;
+ adc->ADC_CHER = OPENPICC_ADC_FIELD_STRENGTH;
+}
personal git repositories of Harald Welte. Your mileage may vary