Wim van der Vegt
/
Spiker
Test program for Spikes when measuring 2 channels in Timer1/MAT1:0 triggering mode.
Embed:
(wiki syntax)
Show/hide line numbers
adc.h
00001 /* mbed Library - ADC 00002 * Copyright (c) 2010, sblandford 00003 * released under MIT license http://mbed.org/licence/mit 00004 */ 00005 00006 #ifndef MBED_ADC_H 00007 #define MBED_ADC_H 00008 00009 #include "mbed.h" 00010 00011 #define XTAL_FREQ 12000000 00012 #define MAX_ADC_CLOCK 13000000 00013 00014 //veg: Corrected (was 64). 00015 #define CLKS_PER_SAMPLE 65 00016 00017 class ADC { 00018 public: 00019 00020 //Initialize ADC with ADC maximum sample rate of 00021 //sample_rate and system clock divider of cclk_div 00022 //Maximum recommened sample rate is 184000 00023 ADC(int sample_rate, int cclk_div); 00024 00025 //Enable/disable ADC on pin according to state 00026 //and also select/de-select for next conversion 00027 void setup(PinName pin, int state); 00028 00029 //Return enabled/disabled state of ADC on pin 00030 int setup(PinName pin); 00031 00032 //Enable/disable burst mode according to state 00033 void burst(int state); 00034 00035 //Select channel already setup 00036 void select(PinName pin); 00037 00038 //Return burst mode enabled/disabled 00039 int burst(void); 00040 00041 /*Set start condition and edge according to mode: 00042 0 - No start (this value should be used when clearing PDN to 0). 00043 1 - Start conversion now. 00044 2 - Start conversion when the edge selected by bit 27 occurs on the P2.10 / EINT0 / NMI pin. 00045 3 - Start conversion when the edge selected by bit 27 occurs on the P1.27 / CLKOUT / 00046 USB_OVRCRn / CAP0.1 pin. 00047 4 - Start conversion when the edge selected by bit 27 occurs on MAT0.1. Note that this does 00048 not require that the MAT0.1 function appear on a device pin. 00049 5 - Start conversion when the edge selected by bit 27 occurs on MAT0.3. Note that it is not 00050 possible to cause the MAT0.3 function to appear on a device pin. 00051 6 - Start conversion when the edge selected by bit 27 occurs on MAT1.0. Note that this does 00052 not require that the MAT1.0 function appear on a device pin. 00053 7 - Start conversion when the edge selected by bit 27 occurs on MAT1.1. Note that this does 00054 not require that the MAT1.1 function appear on a device pin. 00055 When mode >= 2, conversion is triggered by edge: 00056 0 - Rising edge 00057 1 - Falling edge 00058 */ 00059 void startmode(int mode, int edge); 00060 00061 //Return startmode state according to mode_edge=0: mode and mode_edge=1: edge 00062 int startmode(int mode_edge); 00063 00064 //Start ADC conversion 00065 void start(void); 00066 00067 //Set interrupt enable/disable for pin to state 00068 void interrupt_state(PinName pin, int state); 00069 00070 //Return enable/disable state of interrupt for pin 00071 int interrupt_state(PinName pin); 00072 00073 //Attach custom interrupt handler replacing default 00074 void attach(void(*fptr)(void)); 00075 00076 //Restore default interrupt handler 00077 void detach(void); 00078 00079 //Append custom interrupt handler for pin 00080 void append(PinName pin, void(*fptr)(uint32_t value)); 00081 00082 //Unappend custom interrupt handler for pin 00083 void unappend(PinName pin); 00084 00085 //Append custom global interrupt handler 00086 void append(void(*fptr)(int chan, uint32_t value)); 00087 00088 //Unappend custom global interrupt handler 00089 void unappend(void); 00090 00091 //Set ADC offset to a value 0-7 00092 void offset(int offset); 00093 00094 //Return current ADC offset 00095 int offset(void); 00096 00097 //Return value of ADC on pin 00098 int read(PinName pin); 00099 00100 //Return DONE flag of ADC on pin 00101 int done(PinName pin); 00102 00103 //Return OVERRUN flag of ADC on pin 00104 int overrun(PinName pin); 00105 00106 //Return actual ADC clock 00107 int actual_adc_clock(void); 00108 00109 //Return actual maximum sample rate 00110 int actual_sample_rate(void); 00111 00112 //Return pin ID of ADC channel 00113 PinName channel_to_pin(int chan); 00114 00115 //Return pin number of ADC channel 00116 int channel_to_pin_number(int chan); 00117 00118 00119 private: 00120 int _pin_to_channel(PinName pin); 00121 uint32_t _data_of_pin(PinName pin); 00122 00123 int _adc_clk_freq; 00124 void adcisr(void); 00125 static void _adcisr(void); 00126 static ADC *instance; 00127 00128 uint32_t _adc_data[8]; 00129 void(*_adc_isr[8])(uint32_t value); 00130 void(*_adc_g_isr)(int chan, uint32_t value); 00131 void(*_adc_m_isr)(void); 00132 }; 00133 00134 #endif
Generated on Fri Jul 15 2022 21:31:56 by 1.7.2