4 directional EMG control of the XY table. Made during my bachelor end assignment.

Dependencies:   C12832_lcd HIDScope mbed-dsp mbed

main.cpp

Committer:
jessekaiser
Date:
2015-06-10
Revision:
54:abb7f76a0473
Parent:
53:f783b3192dbb
Child:
55:fa6d5ee5c854

File content as of revision 54:abb7f76a0473:

#include "mbed.h"
#include "C12832_lcd.h"

#define P_GAIN 0.995

DigitalOut Dir(p23);
PwmOut Step(p24);
AnalogIn Pos1(p17); 
AnalogIn Pos2(p18); 
DigitalOut Enable(p16);
DigitalOut MS1(p27);
DigitalOut MS2(p28);
DigitalOut MS3(p29);
AnalogIn Pot1(p19);
AnalogIn Pot2(p20);
C12832_LCD lcd;

Serial pc(USBTX, USBRX);

int main()
{
    Enable = 0;
    float setpoint = 7000; //Frequentie 
    float step_freq = 1;
    MS1 = 1;
    MS2 = 0;
    MS3 = 0;
    
    Step.period(1./step_freq); // 1 kHz, vanaf 2,5 kHz doet de motor het niet meer.
    Step.write(0.5); // Duty cycle van 50%
   
    Enable = 1;
    while (1) {
        Dir = 0;
        float new_step_freq;
        new_step_freq = ((1-P_GAIN)*setpoint) + (P_GAIN*step_freq);
        step_freq = new_step_freq;
        Step.period(1.0/step_freq);
        
        pc.printf("%.2f %.0f \n", Pos1.read(), step_freq);
        wait(0.01); //Hier nog ticker inbouwen

    }
}