main.cpp 1.63 KB
Newer Older
Martin Horauer's avatar
Martin Horauer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* mbed Example Program
 * Copyright (c) 2006-2014 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/******************************************************************* Includes */
#include "mbed.h"

/******************************************************************** Globals */
21
22
23
24
25
26
/* create an object of class AnalogOut: "aout"
   see drivers/AnalogOut.h
   the parameter P14_8 is declared in
   targets/TARGET_Infineon/TARGET_XMC4XXX/TARGET_XMC4500/PinNames.h
*/
AnalogOut aout (P14_8);
Martin Horauer's avatar
Martin Horauer committed
27
28
29
30
31

/****************************************************************** Functions */
/**
 * Main Function
 */
32
33
34
35
36
37
38
int main (void)
{
	const double pi = 3.141592653589793238462;
	const double amplitude = 0.4f;
	const double offset = 65535;
	double rads = 0.0;
	uint16_t sample = 0;
Martin Horauer's avatar
Martin Horauer committed
39

40
41
42
43
44
45
46
47
48
49
50
51
	while (1) {
		/* Generate Sinus */
		for (int i = 0; i < 360; i++) {
			rads = (pi * i) / 180.0f;
			sample = (uint16_t) (amplitude * (offset * (cos (rads + pi))) + offset);
			/* invoke the method .write_u16() on the object aout
			   see drivers/AnalogOut.h
			   this method outputs an anlog value on P14_8 using the DAC
			*/
			aout.write_u16 (sample);
		}
	}
Martin Horauer's avatar
Martin Horauer committed
52
53
}
/*EOF*/