HERE’s the extract of what I wrote in chat… I hope this is clearer.
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)
… this is the function that is called from within a while loop.
in Matlab I have
if ~strcmp(LED, oldLED)
fprintf(FEZPort, ['' num2str(LED)])
oldLED = LED;
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.ToString() + "\r\n";
byte buffer2 = Encoding.UTF8.GetBytes(cs);
UART.Write(buffer2, 0, buffer.Length);
the setLED then runs the first code I pasted