hello:
i am really new to arduino and i was wondering if i could use one to get signals come from an encoder, send them to labview for processing and get an output signal (PWM) from the arduino to the motor. and i was wondering since the encoders frequency would be about 20khz, do i need 2 arduinos:
one for sending the encoder signals to the pc
and the other one for sending the pwm to the motor
or is one sufficient to do both jobs? if yes could some one help me with the programming
to be specific,im trying to reduce the steady state error of a dc motor by getting values of its current speed (from an encoder), comparing it to the reference speed and using a pi controller (in labview which is already done) and the sending the analogue signal to the arduino which sends a PWM signal to the dc motor
20,000 pulses per second from an encoder? That's a lot. What speed is the motor running at? What is it doing? What kind of encoder is it? The Arduino might me able to handle that number of pulses and do PWM, but it isn't going to send 20,000 anything and get 20000 responses per second to/from labview.
the encoder has 300 lines per revolution, and the dc motor goes up to 4000 rpm which gives you a frequency of 20khz
but the question is how do i program the arduino to do those four tasks
any hint (or a sketch :P) is appreciated
Perhaps, it would be better if you talked about the project in general terms, first. Can the motor go in both directions? How much load on the motor? What voltage and current draw? What will you be applying PWM to?
it's not that any of those matter but it's a 24V, 15W motor it wont be moving/having any load, it's just the first stage where im going to see how much the steady state error of the motor is going to improve on labview by observing the signal given by the encoder, processing it and sending the compensating signal. thats all
You can't directly connect a 24V 15W motor to the Arduino. So, it most certainly does matter what you are going to feed a PWM signal to. If that whatever it is introduces delay, you have to take that into account.
There are examples around of reading an encoder. It's not that difficult. If the motor turns both directions, it's a little more challenging, but the logistics have all been worked out. The playground is having issues right now, but there are examples then (when it is working again).
Sending data to labview is a simple Serial.write() or Serial.print(). Getting responses is a simple matter, using Serial.available() and Serial.read(). Setting a pin to a PWM level is trivial.
regarding the connection between the motor and the arduino there is going to be a mosfet (since it's going to be moving in one direction), buffer and an amplifier.
regarding the encoder examples cant i just read the incoming signal and send it to the labview
and what about the three other tasks do i use multiplexing
You only communicate to labView through the serial port so you are not going to send a 20kHz signal to it.
A multiplexer is for putting lots of signals out of a few pins, it is nothing to do with multi tasking.
We ask these questions because your specification is nieavly over optimistic.
cant i just read the incoming signal and send it to the labview
Sure you can. The only issue is the signal is just a tick, tick, tick. You need to use an interrupt handler, so you don't miss any ticks.
The encoder output is not an analog signal.
You can send the ticks to labview, but nowhere near as fast as they occur.
The Arduino can do PID stuff, too. Whether it will be fast enough, or not, depends on how much variation there is in the speed of the motor.
Why you need a constant speed for a motor that is doing nothing remains a mystery. As Grumpy_Mike points out, the more information you can share, the more likely it is that we can suggest other (practical) ways of accomplishing your goal.
PaulS:
Why you need a constant speed for a motor that is doing nothing remains a mystery. As Grumpy_Mike points out, the more information you can share, the more likely it is that we can suggest other (practical) ways of accomplishing your goal.
well im using a different approach, other than PID it's called phase locked loop control i might be adding some load to the motor, to see if the motor would get effected and then compensated and i would like to see what is happening to the output of the motor that why im using the labview.
as for the code i thought of following the following sequence in a loop would it work:
encoder signal into arduino
2)encoder signal to pc
3)pc signal in arduino (when available)
4)pc signal to motor as PWM
since since as far as i know and what i meant by multiplexing is that it does those steps sequentially but fast enough to make it look like it's multitasking
In what form? How often? The encoder pulse will be useless to the PC, so you need to create some other representation that the PC can understand.
3)pc signal in arduino (when available)
The Arduino can read how much data is available to read, using Serial.available(). It can read that data, one byte at a time, using Serial.read().
You need to define what the PC will be sending back. Simplest, of course, is a single byte whenever the PWM value (which is also a byte) needs to change.
4)pc signal to motor as PWM
Keep in mind that PWM on the Arduino is limited to 256 discrete values. Whether than is sufficient to "control your motor" or not is still a mystery.
A phase locked loop is a well known hardware control package, however it would appere that you are trying to implement it in software. That is a much more difficult task because you have to input rates and also implement a filter after the Phase comparator. I assume your motor and the encoder is the VCO. The response of a PLL is defined by the filter and so you are going to have to implement a DSP filter which is not the arduino's strong point.
Your list of the sequence you have is very vague and needs fleshing out.
In what form? How often? The encoder pulse will be useless to the PC, so you need to create some other representation that the PC can understand.
wouldnt the pc receive it serially as an analogue signal? isnt the encoders signal an analogue?
the labview code should then be able to show the signal as pulses (thats what i want) and extract the amplitude, frequency and phase and process it from there as for how often it should be able to get about 500 samples/s (sorry im being optimistic again :)) how about 100.
PaulS:
4)pc signal to motor as PWM
Keep in mind that PWM on the Arduino is limited to 256 discrete values. Whether than is sufficient to "control your motor" or not is still a mystery.
sorry but i kind of got lost here.
as for the pll program i already have it written in labview but it was origianlly intended for an NI DAQ. however i think it can be modified using visa if the arduino successfully works (being optimistic again :P)
wouldnt the pc receive it serially as an analogue signal?
No.
isnt the encoders signal an analogue?
No.
the labview code should then be able to show the signal as pulses (thats what i want) and extract the amplitude, frequency and phase and process it from there
The purpose of an encoder is to count steps. A step either occurred or it didn't. That is the definition of a digital event. The number of steps is an integer value.
There is just no way to get an analog value that means anything from an encoder.
Even if there were, there is no way that the PC can make use of an analog value. What would 3.7 volts mean?
extract the amplitude, frequency and phase
Of a DC signal? Amplitude, yes. Frequency - has no meaning. Phase? No meaning.
as the signal is recieved by the pc what form would it be in?
A byte variable, containing a value in the range 0 to 255.
That is the ONLY thing that you can pass via the serial port. To any application. From any device.
what does the byte that is revieved by the pc represent in this case isnt it the pulses from the encoder?
I don't know. I don't know what YOU will be sending to the serial port. You can't send a pulse to the serial port, so, no, it won't be pulses from the encoder. You can only send data.
lets say that i decided to calculate the period between each pulse and calculate the frequency then it would be possible to send that value to the pc, right?
then what about the phase how can i calculate that?
and the voltage is it's value always 3.5 volts
im thinking of finding the values of those three in the arduino and then sending them to labview, would that work for a real time application