Proxxon IBS/E PWM Drehzahlregelung


hallo,

ich möchte bei einem proxxon bohrschleifer ibs/e per pwm die drehzahl mit eine arduino regeln.
der bohrschleifer soll allerdings auch ohne angeschlossenes pwm-signal  funktionieren. dazu habe ich folgendes gefunden:
http://bienonline.magix.net/public/mf70-drehzahl.html.
die drehzahl soll mit einem hallsensor erfasst werden und somit die ist-geschwindigkeit zur soll-geschwindigkeitgeregelt werden.

hier ein paar zeichnungen der schaltung:

bohrschleifer und pwm eingangsschaltung:
http://www.mikrocontroller.net/attachment/223840/proxxon_pwm.png

fritzing sketch:
http://www.mikrocontroller.net/attachment/225599/proxxon_rpm_control_steckplatine.png

dazu habe ich versucht folgende codes zu vereinen:

pwm-code:

code: [select]
int sensorpin = 0;
int pwmpin = 9;
int sensorvalue = 0;

void setup() {
  pinmode(pwmpin, output);
  // initialize serial communication @ 9600 bits per second:
  tccr1b = tccr1b & 0b11111000 | 0x01;
  serial.begin(9600);
}

// loop routine runs on , on again forever:
void loop() {
  // read input on analog pin 0:
  sensorvalue = analogread(sensorpin);
  // print out value read:
  serial.println(sensorvalue);
  analogwrite(pwmpin,sensorvalue / 4);
  delay(1);        // delay in between reads stability
}


drehzahlerfassung:

code: [select]
volatile short rpmcount;
volatile int status;

unsigned int rpm;

unsigned long timeold;
void rpm_fun(){
  rpmcount++;   
  if (status == low) {
    status = high;
  }else{
     status = low;
  }
   //digitalwrite(statuspin, status);
}

void setup(){
  serial.begin(9600);
  //interrupt 0 digital pin 2, ir detector connected
  //triggers on falling (change high low)
  attachinterrupt(0, rpm_fun, rising);
 
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  status = low;
}
void loop() {
   //update rpm every second
   delay(1000);
   detachinterrupt(0);
   rpm = 30*1000/(millis() - timeold)*rpmcount;
   timeold = millis();
   rpmcount = 0;

   serial.print(rpm,dec);
   serial.print(" =u/min\n");

   attachinterrupt(0, rpm_fun, rising);
  }


pid-regelung: http://playground.arduino.cc/code/pidlibrary

code: [select]
/********************************************************
* pid basic example
* reading analog input 0 control analog pwm output 3
********************************************************/

#include <pid_v1.h>

//define variables we'll connecting to
double setpoint, input, output;

//specify links , initial tuning parameters
pid mypid(&input, &output, &setpoint,2,5,1, direct);

void setup()
{
  //initialize variables we're linked to
  input = analogread(0);
  setpoint = 100;

  //turn pid on
  mypid.setmode(automatic);
}

void loop()
{
  input = analogread(0);
  mypid.compute();
  analogwrite(3,output);
}


mein versuch dieses zu vereinen:

code: [select]
#include <pid_v1.h>

// pins
const int pwmpin = 9;   // pwm output pin
const int rpmint = 0;  // rpm input interupt (int 0 pin 2)

//rpm variablen
volatile short rpmcount;
volatile int state;
double rpm;

//pid variablen
double setrpm, output, kp = 1, ki = 1, kd = 0;
unsigned long timeold;

//specify links , initial tuning parameters
pid mypid(&rpm, &output, &setrpm, kp,ki,kd, direct);

void rpm_fun(){
  rpmcount++;   
  if (state == low) {
    state = high;
  }else{
     state = low;
  }
   //digitalwrite(statuspin, state);
}

void setup(){
  serial.begin(9600); //serial conection
 
  //set pin modes
  pinmode(pwmpin, output);
 
  // set pwm frequncy bin 9 31.250 khz
  tccr1b = (tccr1b & 0b11111000) | 0x02;
 
  //triggers on falling (change high low)
  attachinterrupt(rpmint, rpm_fun, falling);
 
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
  state = low;
 
  setrpm = 0;
 
  //turn pid on
  mypid.setmode(automatic);
 
 
 
}
void loop() {
 
  // set rpm per serial conection
  if (serial.available() > 0) {
    setrpm = serial.read();
  } else {
    setrpm = 0;
  }
 
  delay(1000);
  detachinterrupt(rpmint);
  rpm = 30*1000/(millis() - timeold)*rpmcount;
  timeold = millis();
  rpmcount = 0;
 
  serial.print("soll: ");
  serial.print(setrpm);
  serial.print(" u/min | ");
 
  serial.print("ist: ");
  serial.print(rpm);
  serial.print(" u/min \n");
 
  mypid.compute();
 
  analogwrite(pwmpin,255-output);
 
  attachinterrupt(rpmint, rpm_fun, falling);
  }


nur ist der versuch mit wenig erfolg gekrönt, da nun periodisch pwm signale von 0 bzw. 255 erzeugt werd, die den proxxon immer nur kurz voll beschleunigen und dann wieder austruddeln lassen.
vielleicht kann mir hier im forum jemand auf die sprünge helfen.

gruß
borsti87

kann mir denn keiner helfen? :(


Arduino Forum > International > Deutsch (Moderator: uwefed) > Proxxon IBS/E PWM Drehzahlregelung


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support