Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

multi threading problem


  • Please log in to reply
3 replies to this topic

#1 JeroenG

JeroenG

    Member

  • Members
  • PipPip
  • 13 posts

Posted 13 May 2013 - 05:04 PM

Hi

I use netduino plus

Which I/O pins are compatible for multi threading.
I have a problem with multithreading.

 

Code:

Imports Microsoft.SPOT

Imports Microsoft.SPOT.Hardware

Imports SecretLabs.NETMF.Hardware

Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Module Module1

Dim button As New InputPort(Pins.ONBOARD_SW1, False, Port.ResistorMode.Disabled)

Dim Sensor As New InputPort(Pins.GPIO_PIN_D0, False, Port.ResistorMode.Disabled)

Dim Motor As New OutputPort(Pins.GPIO_PIN_D1, False)

Dim StepMotor As New OutputPort(Pins.GPIO_PIN_D2, False)

Dim tMotor As New Thread(AddressOf RotateMotor)

Dim tStepMotor As New Thread(AddressOf RotateStepMotor)

Sub Main()

' write your code here

tMotor.Start()

tStepMotor.Start()

Do

 

Loop

 

End Sub

 

Sub RotateMotor()

If button.Read = True Then

Do

Motor.Write(True)

Thread.Sleep(1)

Motor.Write(False)

Thread.Sleep(63)

Loop Until buton.Read = False

End If

End Sub

 

Sub RotateStepMotor()

If Sensor.Read = True Then

Do

StepMotor.Write(True)

Thread.Sleep(20)

StepMotor.Write(False)

Thread.Sleep(20)

Loop Until Sensor.Read = False

End If

End Sub

 

End Module

 

 

[color=rgb(0,0,0);]If sensor is active then all is OK.[/color]

 

[color=rgb(0,0,0);]If button is active then all is OK.[/color]

[color=rgb(0,0,0);] [/color]

[color=rgb(0,0,0);]If button and sensor are active then everything is not OK.[/color]

[color=rgb(0,0,0);] [/color]

The output signal of Motor is the same as the output signal of Stepmotor.

What is wrong?

 

Thanks
 

 

 

 



#2 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 13 May 2013 - 06:57 PM

Hi! Start by removing the do...loop in Sub Main, instead use Thread.Sleep(Timeout.Infinite). Next, both your threads will exit as soon as sensor and button reads true respectively. Once a thread exits its method, it stops running and won't get called again per se. Therefore, replace the "loop untill..." with just "loop" in each of the corresponding methods and it should work better. Better still would be for you to declare both sensor and button as Interrupt ports and then use the interrupt to turn motor rotation on and off depending the edge being high or low.

#3 JeroenG

JeroenG

    Member

  • Members
  • PipPip
  • 13 posts

Posted 13 May 2013 - 07:10 PM

Thanks

 

I will try tomorrow.  



#4 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 13 May 2013 - 09:48 PM

I forgot to say earlier; move the if block to inside the do...loop for both threads.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.