Sin wave generation class using D/A converter(LPC1768)
Dependents: agic_touch_panel_v3
Revision 0:e934e95962bd, committed 2014-06-24
- Comitter:
- macht
- Date:
- Tue Jun 24 04:44:48 2014 +0000
- Commit message:
- Sin wave generation class using D/A converter(LPC1768)
Changed in this revision
Sinwave.cpp | Show annotated file Show diff for this revision Revisions of this file |
Sinwave.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sinwave.cpp Tue Jun 24 04:44:48 2014 +0000 @@ -0,0 +1,24 @@ +#include "mbed.h" +#include "Sinwave.h" + +Sinwave::Sinwave(PinName DAport,float amplitude,float frequency):DAport_(DAport){ + int i; + float pi = 3.1415; + cycle_ = 1.0/(frequency*10.0); + for(i = 0;i < 10;i++){ + outputs_[i] = amplitude*0.5 * (float)sin(2*pi*frequency*cycle_*i) + 0.5; + } +} +void Sinwave::update(){ + static int i = 0; + DAport_.write(outputs_[i]); + i++; + i = i % 10; +} +void Sinwave::start(){ + output_int_.attach(this,&Sinwave::update,cycle_); +} +void Sinwave::stop(){ + output_int_.detach(); +} + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Sinwave.h Tue Jun 24 04:44:48 2014 +0000 @@ -0,0 +1,17 @@ +#ifndef SINWAVE_H_ +#define SINWAVE_H_ +#include"mbed.h" + +class Sinwave{ + public: + Sinwave(PinName DAport,float amplitude,float frequency); + void start(); + void stop(); + private: + void update(); + float outputs_[10]; + float cycle_; + Ticker output_int_; + AnalogOut DAport_; +}; +#endif \ No newline at end of file