TMS320F28335 Library  1.0
Documentation
adc.c
Go to the documentation of this file.
1 
8 #include "adc.h"
9 #include "global_defines.h"
10 
16 void init_ADC(){
17  int i=0;
18 
19  // Define ADCCLK clock frequency ( less than or equal to 25 MHz )
20  EALLOW; // Allow register writes
21  TMC_BASE_SCR->HISPCP = 0x3; // Set High-Speed Peripheral Clock Prescaler to 3 for High speed clock = SYSCLKOUT/6
22  (*ADC_Cal) (); // ADCREFSEL and ADCOFFTRIM must be initialized
23  EDIS; // protect register
24 
25  __asm(" RPT #10 || NOP"); // Provides the required delay between writes to ADCTRL1
26 
27  TMC_BASE_ADC->TRL1 |= (0x1 << 4); // Setup cascaded sequencer mode
28  TMC_BASE_ADC->TRL3 |= (0x1); // Setup simultaneous sampling mode
29  TMC_BASE_ADC->MAXCONV |= (0x0007); // 8 double conv's (16 total)
30 
31  TMC_BASE_ADC->CHSELSEQ1 &= ~(0xF); // Setup conv from channels ADCINA0 and ADCINB0
32  TMC_BASE_ADC->CHSELSEQ1 |= (0x1 << 4); // Setup conv from channels ADCINA1 and ADCINB1
33  TMC_BASE_ADC->CHSELSEQ1 |= (0x2 << 8); // Setup conv from channels ADCINA2 and ADCINB2
34  TMC_BASE_ADC->CHSELSEQ1 |= (0x3 << 12); // Setup conv from channels ADCINA3 and ADCINB3
35  TMC_BASE_ADC->CHSELSEQ2 |= (0x4); // Setup conv from channels ADCINA4 and ADCINB4
36  TMC_BASE_ADC->CHSELSEQ2 |= (0x5 << 4); // Setup conv from channels ADCINA5 and ADCINB5
37  TMC_BASE_ADC->CHSELSEQ2 |= (0x6 << 8); // Setup conv from channels ADCINA6 and ADCINB6
38  TMC_BASE_ADC->CHSELSEQ2 |= (0x7 << 12); // Setup conv from channels ADCINA7 and ADCINB7
39 
40  TMC_BASE_ADC->TRL3 |= 0x00E0; // Power up ADC circuits
41 
42  for(i=0; i<3000; i++){
43  __asm(" RPT #255 || NOP"); // Provides the required delay of 5ms
44  }
45 
46  TMC_BASE_ADC->TRL2 = 0x2000; // Start-of-conversion
47 }
48 
57  switch(adc_pin){
58  case 0 ... 15: TMC_BASE_ADC->TRL2 = 0x2000; // Start-of-conversion
59  __asm(" RPT #255 || NOP"); // Wait for conversion
60  return (TMC_BASE_ADC_RESULT->RESULT[adc_pin]); // Return result value (0-4095)
61  default: return -1;
62  }
63 }
TMC_BASE_SCR.h
System-Control-Register header file.
int16
int int16
16 Bit Variable: - 32.768 .. 32.767
Definition: global_defines.h:17
adc.h
Header file for ADC module.
TMC_BASE_ADC.h
ADC-Register header file.
global_defines.h
Header file for global defines.
ADC_getValue
int16 ADC_getValue(Uint16 adc_pin)
Get Value of ADCIN-Pin.
Definition: adc.c:56
Uint16
unsigned int Uint16
16 Bit Variable: 0 .. 65.535
Definition: global_defines.h:21
init_ADC
void init_ADC()
Init ADC.
Definition: adc.c:16