Lösung des Praktikums Systementwurf
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sine.c 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "system/task_sine.h"
  2. #include "system/data_channel.h"
  3. #include "system/float_word.h"
  4. #include <math.h>
  5. #include <stdio.h>
  6. typedef struct {
  7. float value;
  8. } Result;
  9. void generateSinusCurve(float samples_per_period, float phase, float amplitude, Result res[]) {
  10. float delta_phase = 2.0 * M_PI / samples_per_period;
  11. float current_phase = phase;
  12. for (int i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
  13. res[i].value = amplitude * sinf(current_phase);
  14. current_phase += delta_phase;
  15. }
  16. }
  17. int task_sine_run( void * data ) {
  18. sine_config * task = (sine_config *) data;
  19. uint32_t data_channel_base = task -> base.sink;
  20. data_channel_clear( data_channel_base );
  21. float_word res;
  22. //float samples_per_period = 32.0;
  23. float samples_per_period = task ->samples_per_periode;
  24. float phase = task-> phase;
  25. float amplitude = task -> amplitude;
  26. Result results[DATA_CHANNEL_DEPTH];
  27. generateSinusCurve(samples_per_period, phase, amplitude, results);
  28. for (int i = 0; i < DATA_CHANNEL_DEPTH; ++i) {
  29. //printf("Wert %d: %f\n", i, results[i].value);
  30. res.value = results[i].value;
  31. data_channel_write( data_channel_base, res.word);
  32. }
  33. return 0;
  34. }