PDA

View Full Version : Motor Controller MC 2100



colocolo
09-11-2012, 11:27 AM
Hello,

i want to connect a treadmill with an arduino because i want to control the treadmill with an IR sensor.
the idea is that the sensor tracks the distance so that it could keep me on the right spot.
i already connected the arduino leonardo with the motor controller for reading an signal.
i used this code:


//Reads a PWM signal's duty cycle and frequency.
#define READ_PIN 13

#define PWM_OUTPUT 10

static double duty;
static double freq;
static long highTime = 0;
static long lowTime = 0;
static long tempPulse;

void setup(){
pinMode(READ_PIN,INPUT);
Serial.begin(9600);
analogWrite(PWM_OUTPUT,230);
}

void loop(){
readPWM(READ_PIN);
Serial.println(freq);
Serial.println(duty);
}

//Takes in reading pins and outputs pwm frequency and duty cycle.
void readPWM(int readPin){
highTime = 0;
lowTime = 0;

tempPulse = pulseIn(readPin,HIGH);
if(tempPulse>highTime){
highTime = tempPulse;
}

tempPulse = pulseIn(readPin,LOW);
if(tempPulse>lowTime){
lowTime = tempPulse;
}

freq = ((double) 1000000)/(double (lowTime+highTime));
duty = (100*(highTime/(double (lowTime+highTime))));
}


it gave me the values 47,... and 50,...
so it has 50 HZ frequency. 47 must be the duty cycle, cause i also measured with another code 9,3 msec.

i guess i have to use a NE555 timer circuit am i wrong? so how would i connect it to the arduino?
would this whole method work?

thanks

Mike Amick
09-11-2012, 01:51 PM
I'm not sure I understand your intent. "Keep you in the right spot" ? the 2100 already
does a nice job of speed maintaining using a hall effect sensor and other internal components.
If you want to use the Arduino just for a fun project .. no problem. The 2100 is a controller
that needs external pulses to control it. Most treadmill controllers make it real easy by using
a pot to control the speed .. but not the 2100 .. You shouldn't need a 555 ... the Arduino
is perfect for supplying these pulses and you already seem well versed in programming it.

colocolo
09-11-2012, 02:08 PM
Oops, I thought i mentioned it. that is not mine code.
so the idea is to get the belt start moving if a i lean forward. so when i will enter a defined distance interval it will start to move.
i need this for not falling off the treadmill, cause i wanna use it with a VR headset.
i have no idea how to generate those pulses by code.
this is a thread i found how it canwork http://forum.allaboutcircuits.com/archive/index.php/t-51061.html But it didnt work.
perhaps i implemented the code wrong.

lwalker
09-11-2012, 08:39 PM
You sure you're on the right board?

Mike Amick
09-11-2012, 08:54 PM
Colocolo .. that is a kickass project .. and really neat .. a VR enviroment where you actually have
to walk .. that is sooo cool.

But .. lwalker is right .. you are totally welcome here .. but .. would find much better help on
a Arduino forum. Good luck

colocolo
09-12-2012, 06:05 AM
i didnt get the meaning of the url bbs.homeshopmachinist at once. i am from germany. so there is a little linguistic barrier.
i only read some threads about micro controllers here and i thought i would have more luck here cause the arduino forum couldnt help till now.

macona
09-12-2012, 06:29 AM
Probably the best thing to do is get it working with a 555 setup as an oscillator. Find out what it wants for the carrier frequency. Then you can set up the arduino to match.

The Artful Bodger
09-12-2012, 06:33 AM
I think you can use the internal timers of the Arduio to create interrupts so you would not need a 555 to provide interrupts.

colocolo
09-12-2012, 12:56 PM
I think you can use the internal timers of the Arduio to create interrupts so you would not need a 555 to provide interrupts.

i tried it with an interrupt. this is the code:


#include "TimerOne.h"




int ledpin=10;
int alle_x_sekunden=1;

void setup() {
pinMode(ledpin, OUTPUT);
Timer1.initialize(alle_x_sekunden*20000);
Timer1.pwm(10, 5120);
Timer1.attachInterrupt(callback);
}

void callback() {
digitalWrite(ledpin, digitalRead(ledpin) ^ 1);
}


void loop() {
}


but it still doesnt work. any idea how to set up a better code?