Sin wave generation class using D/A converter(LPC1768)

Dependents:   agic_touch_panel_v3

Committer:
macht
Date:
Tue Jun 24 04:44:48 2014 +0000
Revision:
0:e934e95962bd
Sin wave generation class using D/A converter(LPC1768)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
macht 0:e934e95962bd 1 #include "mbed.h"
macht 0:e934e95962bd 2 #include "Sinwave.h"
macht 0:e934e95962bd 3
macht 0:e934e95962bd 4 Sinwave::Sinwave(PinName DAport,float amplitude,float frequency):DAport_(DAport){
macht 0:e934e95962bd 5 int i;
macht 0:e934e95962bd 6 float pi = 3.1415;
macht 0:e934e95962bd 7 cycle_ = 1.0/(frequency*10.0);
macht 0:e934e95962bd 8 for(i = 0;i < 10;i++){
macht 0:e934e95962bd 9 outputs_[i] = amplitude*0.5 * (float)sin(2*pi*frequency*cycle_*i) + 0.5;
macht 0:e934e95962bd 10 }
macht 0:e934e95962bd 11 }
macht 0:e934e95962bd 12 void Sinwave::update(){
macht 0:e934e95962bd 13 static int i = 0;
macht 0:e934e95962bd 14 DAport_.write(outputs_[i]);
macht 0:e934e95962bd 15 i++;
macht 0:e934e95962bd 16 i = i % 10;
macht 0:e934e95962bd 17 }
macht 0:e934e95962bd 18 void Sinwave::start(){
macht 0:e934e95962bd 19 output_int_.attach(this,&Sinwave::update,cycle_);
macht 0:e934e95962bd 20 }
macht 0:e934e95962bd 21 void Sinwave::stop(){
macht 0:e934e95962bd 22 output_int_.detach();
macht 0:e934e95962bd 23 }
macht 0:e934e95962bd 24