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.
ADC_setup.cpp
00001 // ADC_setup.cpp 00002 00003 #include "header.h" 00004 /***************************************************** 00005 variables and defines 00006 ****************************************************/ 00007 00008 int ADC_channel=1; // ADC channel 1 00009 00010 /***************************************************** 00011 subroutines 00012 *****************************************************/ 00013 void ADC_init(){ 00014 00015 PINSEL1=0x00010000; //set AD0.1 pin to 0000 0000 0000 0001 0000 0000 0000 0000 = ADC 00016 PCONP |= (1 << 12); // enable ADC clock 00017 AD0CR = (1 << ADC_channel) // channel 1 00018 | (4 << 8) // This gives us 3MHz 00019 | (0 << 16) // BURST = 0, software control 00020 | (0 << 17) // CLKS = 0 (11-bits) 00021 | (1 << 21) // PDN = 1 00022 | (0 << 22) // TEST1:0 = 00 00023 | (1 << 24) // START = 1 start A/D conversion 00024 | (0 << 27); // EDGE = 0 (CAP/MAT singal falling,trigger A/D conversion) 00025 } 00026 float ADC_read() { 00027 00028 int data; 00029 00030 // start A/D conversion on channel 00031 AD0CR &= (AD0CR & 0xFFFFFF00); 00032 AD0CR |= (1 << ADC_channel) | (1 << 24); 00033 00034 delay_l(); 00035 00036 // wait for it to finish by polling the ADC DONE bit 00037 while((AD0GDR & 0x80000000) == 0) 00038 { 00039 } 00040 00041 // get the data and stop the adc 00042 data = AD0GDR; 00043 AD0CR &= 0xF8FFFFFF; 00044 00045 // shift data and mask to give 8-bit ADC value 00046 data=(data>>8)&0x00000FF; 00047 return data; 00048 }
Generated on Fri Jul 15 2022 11:04:51 by
1.7.2