I’ve made a basic pulse monitor using the FEZ. However I’m having an issue altering the PWM setting via external commands. The problem I am experiencing is that in order for the system to be compatible with many users I need to alter the power sent to the photo-transistor; more sensitive for bigger fingers etc. To do this I alter the PWM by taking a value sent from the UART Com Port, from an external program. This is done within a perpetual loop [while(true)]. When I attempt to send data to the FEZ, the data, being transmitted back through the port, locks up; then stutters and dumps out larger chunks of data. Oh, and the TEST LED doesn’t respond to the new values.
HERE’s the extract of what I wrote in chat… I hope this is clearer.
[line]
I’m having a little difficulty adjusting a PWM pin externally on the fly. The FEZ seems to become stuttered in sending out data to the UART. I’m controlling the output of a PWM pin through Matlab; at least i’m trying to - among other things. I have a small array being sent continuously to the UART and read in correctly in Matlab. I can control the PWM on set-up correctly but… What i am trying to do is send data Back through the UART (to the FEZ) from Matlab to alter the PWM value as it is running. The readings I get from An0 are determined by the level of sensitivity from a phototransistor. So if the readings are not as clear I need to adjust the voltage to said phototransistor and the reading should alter accordingly. The system seems to chock and become stuttered whenever I send data back through the UART. I can communicate perfectly with Matlab.
I was able to send data cleanly and get the FEZ to repeat the data back whilst adding more info…
“Data received : #####” etc. It does blow-out chunks on data intermittently kind of all stuttered But not uniformly as I had expected and also Matlab complains that the bit terminator times out too
public static void setLED(String volts)
{
byte x = byte.Parse(volts);
if (x > 0 & x < 100)
{
IR_LED.Set(10000, x);
}
}
… this is the function that is called from within a while loop.
in Matlab I have
if ~strcmp(LED, oldLED)
fprintf(FEZPort, ['' num2str(LED)])
disp(LED)
oldLED = LED;
end
it clams “Warning: A timeout occured before the Terminator was reached”. Now normally this means that the bitstop is never rached but… this only happens when i try to alter the PWM
It works fine when I dont alter the PWM on the fly
I alter the PWM with the Matlab code above the fprintf command sends data to the COM port; called FEZPort in this case. It sends a string holding the numerical values.
on the FEZ side I have:
read_count = UART.Read(rx_byte, 0, 1);
if (read_count > 0)// do we have data
{
string cs = "You typed: " + rx_byte[0].ToString() + "\r\n";
byte[] buffer2 = Encoding.UTF8.GetBytes(cs);
UART.Write(buffer2, 0, buffer.Length);
setLED(rx_byte[0].ToString());
}
Sorry Gus… I edited the above post. I hope it makes a little sense. :-[
In a nutshell, I’m trying to alter the PWM setting by receiving data from the COM port on the FEZ. Com port communication works perfectly with Matlab both ways but as soon as I try to adjust the PWM setting, by sending the FEZ values, it causes problems in reading from the device.
Oh dear, I am in a muddle here, I have a pounding headache
Okay let me try and start again…
[line]
I am communicating with a FEZ Domino through Matlab. I successfully read and write data to and from the FEZ Domino through the UART port, in Matlab; using Matlabs serial port functions.
I successfully control the illumination of an LED using the PWM command and all is well. I successfully send data (a small array holding 2 integers) from the FEZ Domino to Matlab perpetually in a while loop. This is read continuously in Matlab without any issues and its displayed on a nice little graph.
I have an LED (or phototransistor) that I would like to adjust its voltage value on the fly, by sending new values to the FEZ Domino from Matlab. I have written some code in both Matlab and on the FEZ Domino (C#) to cater for this. See some extracts above:
The problem I have is this:
When I try to alter the PWM values from Matlab and continue to read the stream of data, the data stream seems to lockup. And then randomly spits out chunks of data and locks again. The LED does not change either.
It could be that I am very tired and have a headache…
Matlab is set to send and receive data asynchronously. I have tested this by sending and receiving data perfectly, to and from the Fez… The issue only reveals itself when I try and alter the PWM values. The FEZ seem to lock up the port stream…
I don’t think the issue is with Matlab. That’s why I needed to ask for help.
Hmmm… It may well be… I’ll do that and let you know. Thank you!
Oh, It only sends two integers at a time (as a String) repeatedly.
The system I’m developing needs to be very fast. I am reading data from both an EEG neural headset over blue-tooth and the FEZ Domino. On a negative note the Domino (at full pelt) is sending data at half the speed of the headset so it is proving to be the bottleneck in the system; thus the reason I had the Domino sending data in an un-paused stream. When it had a pause of 1/100th of a second it was over 6 times slower than the headset.
This is just a minor issue but, might well be what’s causing the problem
Then you need to put the load on your PC not on FEZ. For example, you need to send numbers over UART not strings! Then use this to extract the integer Utility.ExtractValueFromArray(…);
We also have one that extract floats…
Yeah, I have decided to put an old fashioned variable resistor to control the load, and away from the FEZ; I really can’t lose any more speed at this point.
Yeah an op-amp would work but adds unnecessary complexity to the system. I’m just as happy at this point to slap in a manual variable resistor and simply read in through the analogue in pins.
Thanks again for your help guys. And thanks for being understanding to a very tired man yesterday. I could have fell asleep at my desk if my desk wasn’t so close to my bed!