Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp
- Committer:
- WiesjeRoskamp
- Date:
- 2019-10-07
- Revision:
- 2:aee655d11b6d
- Parent:
- 1:b862262a9d14
File content as of revision 2:aee655d11b6d:
#include "mbed.h"
//#include "HIDScope.h"
//#include "QEI.h"
#include "MODSERIAL.h"
//#include "BiQuad.h"
//#include "FastPWM.h"
#include <math.h>
Serial pc(USBTX, USBRX);
Ticker myControllerTicker;
AnalogIn potMeter(A0);
PwmOut fan(D5); // kan ook D6 zijn
DigitalOut fan_dir(D4);
InterruptIn button1(D2);
void direction(void)
{
fan_dir=!fan_dir;
pc.printf("hello");
}
// Feed forward fan speed controller
// Suppose an AnalogIn ’potMeter’ and PWMOut ’fan’
void fanController( )
{
// Determine reference (desired) fan speed
double y_des = potMeter.read();
// Controller (calculate motor torque/pwm)
if( y_des > 1 ) y_des = 1; // y_des must be <= 1
if( y_des < 0 ) y_des = 0; // y_des must be >= 0
double u = pow(y_des, 2.0); // Inverse relation between input and output
// Send to motor
fan.write( u );
pc.printf("u: %.2f\n\r",u);
}
int main()
{
myControllerTicker.attach( fanController, 0.1 ); // Every second
button1.mode(PullUp);
button1.rise(direction);
while( true ) { /* do nothing */ }
return 0;
}