Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
vielex
/
bes_labs_2019
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ff6738b8
authored
Mar 26, 2019
by
vielex
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final version of ADC.c
parent
ce5af639
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
44 deletions
Labware/Lab14_MeasurementOfDistance/ADC.c
Labware/Lab14_MeasurementOfDistance/ADC.c
View file @
ff6738b8
// ADC.c
// ADC.c
// Runs on LM4F120/TM4C123
// Runs on LM4F120/TM4C123
// Provide functions that initialize ADC0 SS3 to be triggered by
// Provide functions that initialize ADC0 SS3 to be triggered by
// software and trigger a conversion, wait for it to finish,
// software and trigger a conversion, wait for it to finish,
// and return the result.
// and return the result.
// Daniel Valvano
// Daniel Valvano
// January 15, 2016
// January 15, 2016
/* This example accompanies the book
/* This example accompanies the book
"Embedded Systems: Introduction to ARM Cortex M Microcontrollers",
"Embedded Systems: Introduction to ARM Cortex M Microcontrollers",
ISBN: 978-1469998749, Jonathan Valvano, copyright (c) 2015
ISBN: 978-1469998749, Jonathan Valvano, copyright (c) 2015
Copyright 2016 by Jonathan W. Valvano, valvano@mail.utexas.edu
Copyright 2016 by Jonathan W. Valvano, valvano@mail.utexas.edu
You may use, edit, run or distribute this file
You may use, edit, run or distribute this file
as long as the above copyright notice remains
as long as the above copyright notice remains
THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
For more information about my classes, my research, and my books, see
For more information about my classes, my research, and my books, see
http://users.ece.utexas.edu/~valvano/
http://users.ece.utexas.edu/~valvano/
*/
*/
#include "ADC.h"
#include "ADC.h"
#include "..//tm4c123gh6pm.h"
#include "..//tm4c123gh6pm.h"
// This initialization function sets up the ADC
// This initialization function sets up the ADC
// Max sample rate: <=125,000 samples/second
// Max sample rate: <=125,000 samples/second
// SS3 triggering event: software trigger
// SS3 triggering event: software trigger
// SS3 1st sample source: channel 1
// SS3 1st sample source: channel 1
// SS3 interrupts: enabled but not promoted to controller
// SS3 interrupts: enabled but not promoted to controller
void
ADC0_Init
(
void
){
void
ADC0_Init
(
void
){
volatile
unsigned
long
delay
;
}
SYSCTL_RCGC2_R
|=
0x00000010
;
// 1) activate clock for Port E
delay
=
SYSCTL_RCGC2_R
;
// allow time for clock to stabilize
GPIO_PORTE_DIR_R
&=
~
0x04
;
// 2) make PE2 input
//------------ADC0_In------------
GPIO_PORTE_AFSEL_R
|=
0x04
;
// 3) enable alternate function on PE2
// Busy-wait Analog to digital conversion
GPIO_PORTE_DEN_R
&=
~
0x04
;
// 4) disable digital I/O on PE2
// Input: none
GPIO_PORTE_AMSEL_R
|=
0x04
;
// 5) enable analog function on PE2
// Output: 12-bit result of ADC conversion
SYSCTL_RCGC0_R
|=
0x00010000
;
// 6) activate ADC0
unsigned
long
ADC0_In
(
void
){
delay
=
SYSCTL_RCGC2_R
;
return
0
;
// replace this line with proper code
SYSCTL_RCGC0_R
&=
~
0x00000300
;
// 7) configure for 125K
}
ADC0_SSPRI_R
=
0x0123
;
// 8) Sequencer 3 is highest priority
ADC0_ACTSS_R
&=
~
0x0008
;
// 9) disable sample sequencer 3
ADC0_EMUX_R
&=
~
0xF000
;
// 10) seq3 is software trigger
ADC0_SSMUX3_R
&=
~
0x000F
;
// 11) clear SS3 field
ADC0_SSMUX3_R
+=
1
;
// set channel Ain1 (PE2)
ADC0_SSCTL3_R
=
0x0006
;
// 12) no TS0 D0, yes IE0 END0
ADC0_ACTSS_R
|=
0x0008
;
// 13) enable sample sequencer 3
}
//------------ADC0_In------------
// Busy-wait Analog to digital conversion
// Input: none
// Output: 12-bit result of ADC conversion
unsigned
long
ADC0_In
(
void
){
unsigned
long
result
;
ADC0_PSSI_R
=
0x0008
;
// 1) initiate SS3
while
((
ADC0_RIS_R
&
0x08
)
==
0
){};
// 2) wait for conversion done
result
=
ADC0_SSFIFO3_R
&
0xFFF
;
// 3) read result
ADC0_ISC_R
=
0x0008
;
// 4) acknowledge completion
return
result
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment