Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:31 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Running multi processes

Author Message
MolsonB
Regular Member

Joined: 25/01/2015
Location: Canada
Posts: 48
Posted: 06:52pm 24 May 2015
Copy link to clipboard 
Print this post

In the MKII world, I'm trying to understand the basics compared to a PC program with services and threads..

How can you run a sub routine that has a loop in it, while still running your main code (in a loop) to do it's main tasks. In a nutshell, I have some LEDS in a loop to do a display (knight rider), while I still want my main program to be reading I/O pins and doing other stuff.

Is it possible, or is the MK world a line by line order only?

One way I was thinking, would be to call each LED display sub routines, and the first line would be to check if it's active or not. Instead of using a pause command to control the LED blinking timing, I'd use the system clock to increment each LED to the next one.

I was thinking of using the SETTICK timer, but each LED display could use a different timer depending on if I want the display to be fast or slow. (Slow for dimming lights, but maybe fast for knight rider moving)
MkII 44pin - v5.0

ColorMax 2 - v4.5
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1328
Posted: 07:14pm 24 May 2015
Copy link to clipboard 
Print this post

Using the PWM command and outputs might be an option. There's a large range of frequencies and duty cycles available which could drive the LED's and they operate in the background while the main program is running. All pins have a max output or sink capability of 10mA though so watch that - you might need to buffer the LED's.

The SETTICK command could then be used for I/O polling of other pins or input buffers &/or calling subs and there can be up to four separate timers operating with SETTICK. There's also the external interrupt pins that can be used for the same things instead of, or along with SETTICK.

GregEdited by paceman 2015-05-26
 
MolsonB
Regular Member

Joined: 25/01/2015
Location: Canada
Posts: 48
Posted: 04:12am 25 May 2015
Copy link to clipboard 
Print this post

I'm going to play around with SETTICK a bit more. I can enable / disable it, and re-initialize to change the period depending which LED show is selected.

I'm using SPI out for the LEDs (DotStar from ADAFruit). Very easy to program compared to their NeoPixel's.
MkII 44pin - v5.0

ColorMax 2 - v4.5
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 04:16am 25 May 2015
Copy link to clipboard 
Print this post

Hi Molson, when you get things rolling with the dotstars, could you post some sample code using the spi?
 
MolsonB
Regular Member

Joined: 25/01/2015
Location: Canada
Posts: 48
Posted: 04:54am 25 May 2015
Copy link to clipboard 
Print this post

Ya, I'm just figuring out how to do the brightness based on their code for Aurdio. Is pretty easy though so far.

They are power hungry though, 1 meter of their 60leds can take 3.5amps at 5volts.
MkII 44pin - v5.0

ColorMax 2 - v4.5
 
MolsonB
Regular Member

Joined: 25/01/2015
Location: Canada
Posts: 48
Posted: 04:28pm 27 May 2015
Copy link to clipboard 
Print this post

  viscomjim said   Hi Molson, when you get things rolling with the dotstars, could you post some sample code using the spi?


Put some sample code here.
http://www.thebackshed.com/forum/forum_posts.asp?TID=7691&PN=1


I'm going play around with SETTICK tonight.
MkII 44pin - v5.0

ColorMax 2 - v4.5
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024