As used for motor testing May / June 2016

Dependencies:   iC_MU mbed-rtos mbed

Fork of SweptSine by Vitec Group

Committer:
ms523
Date:
Tue Mar 22 08:33:17 2016 +0000
Revision:
0:3a132f85c1a8
Child:
1:0f0423207b62
swept sine working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ms523 0:3a132f85c1a8 1 #include "mbed.h"
ms523 0:3a132f85c1a8 2
ms523 0:3a132f85c1a8 3 DigitalOut myled(LED1);
ms523 0:3a132f85c1a8 4 Serial pc (USBTX,USBRX);
ms523 0:3a132f85c1a8 5 Timer t;
ms523 0:3a132f85c1a8 6
ms523 0:3a132f85c1a8 7 int main()
ms523 0:3a132f85c1a8 8 {
ms523 0:3a132f85c1a8 9 float run_time = 5.0;
ms523 0:3a132f85c1a8 10 float start_Hz = 1.0, stop_Hz = 2.0;
ms523 0:3a132f85c1a8 11 float amplitude;
ms523 0:3a132f85c1a8 12
ms523 0:3a132f85c1a8 13
ms523 0:3a132f85c1a8 14 pc.printf("\n\r Enter Start frequency (Hz): ");
ms523 0:3a132f85c1a8 15 pc.scanf("%f", &start_Hz);
ms523 0:3a132f85c1a8 16 pc.printf("%f",start_Hz);
ms523 0:3a132f85c1a8 17
ms523 0:3a132f85c1a8 18 pc.printf("\n\r Enter Stop frequency (Hz): ");
ms523 0:3a132f85c1a8 19 pc.scanf("%f", &stop_Hz);
ms523 0:3a132f85c1a8 20 pc.printf("%f",stop_Hz);
ms523 0:3a132f85c1a8 21
ms523 0:3a132f85c1a8 22 pc.printf("\n\r Enter Amplitude (encoder counts): ");
ms523 0:3a132f85c1a8 23 pc.scanf("%f", &amplitude);
ms523 0:3a132f85c1a8 24 pc.printf("%f",amplitude);
ms523 0:3a132f85c1a8 25
ms523 0:3a132f85c1a8 26 pc.printf("\n\n\r Press any key to start test...");
ms523 0:3a132f85c1a8 27 pc.getc();
ms523 0:3a132f85c1a8 28
ms523 0:3a132f85c1a8 29 float w1 = start_Hz * 3.14159 * 2;
ms523 0:3a132f85c1a8 30 float w2 = stop_Hz * 3.14159 * 2;
ms523 0:3a132f85c1a8 31 float a = (w2 - w1) / (2 * run_time);
ms523 0:3a132f85c1a8 32 float b = w1;
ms523 0:3a132f85c1a8 33 float now;
ms523 0:3a132f85c1a8 34
ms523 0:3a132f85c1a8 35 t.start();
ms523 0:3a132f85c1a8 36
ms523 0:3a132f85c1a8 37 while(t.read() < run_time) {
ms523 0:3a132f85c1a8 38 now = t.read();
ms523 0:3a132f85c1a8 39 pc.printf("\n\r%f",amplitude * sin((a*now*now)+(b*now)));
ms523 0:3a132f85c1a8 40 }
ms523 0:3a132f85c1a8 41
ms523 0:3a132f85c1a8 42 }