Main Site Documentation

Multithreading OneWire and OutputCompare


#1

Hi,

I have several different threads for a weather station I am building. There is a thread to update the display, and a thread for every sensor.

The two threads that I am having a problem are:

  1. A thread that uses GHIElectronics.NETMF.Hardware.OutputCompare to do SerialLCD (driver code found on this website)
  2. A thread reading a DS18B20 thermomter using GHIElectronics.NETMF.Hardware.OneWire.

The problem is that the OneWire thread is interfering with the LCD display thread by producing random jibberish characters on the screen. I have verified this by freezing the thermometer thread in the debugger while all other threads run. I currently have 2 other threads, one monitoring a BMP085 barometric pressure sensor (through I2C) and the other monitoring a HIH-4030 humidity sensor (through AnalogIn), and these do not interfere with the display thread.

Before I go too far into this, does anyone have experience with multiple threads on FEZ and the limitations? Or could this be a case of a software implementation of UART being interrupted by the other thread (temp thread) causing the problem? Although that wouldn’t make sense because I have 2 sensor threads (barometer and humidity) running that don’t mess with the display thread.

BTW: I am so happy with FEZ because I am a C#/.NET developer and it is so easy to build embedded software now with Visual Studio!!! ;D

Greg


#2

You don’t mention what board you’re using, nor what pins you’re using for your input and output devices. That may be relevant in this scenario, so it’s worth posting that info for all to see.

I don’t have any specific experience to add here, except to ask have you made sure you’re thread-safe when you’re updating the values read from the DS18B20? I’m assuming that the display routine is then writing those values out, and you could be stepping on each other that way?


#3

Is the lcd write/update syncronized?


#4

OneWire and OutputComapre are generated in software and both block interrupts to grantee timing. The problem is that when one is used while the other is running you will have problems. Use thread synchronization to use on at once or use hardware serial port for th display. You have 4 UART ports available.


#5

Also, the LCD code can be modified for better timings with the Beta SDK.
OutputCompare now has a blocking option. It only returns when the transfer is complete. Replace Set with SetBlocking(…). This way OneWire cannot interfere with it.


#6

Thank you Gus and Mike for the explanations!

For simplicity, I will put a critical section around both the OneWire and OutputCompare calls so that they cannot both execute at the same time. I believe this should solve my problem.

FEZ rocks!!!