/* 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 */ /* 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); /****************************************************************** Functions */ /** * Main Function */ 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; 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); } } } /*EOF*/