Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Common Practice
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Common Practice

by sting on Sun Dec 05, 2021 12:27 pm

I am building a project that has basic 3 components, the function the project is supposed to do, user interface with a rotary encoder and backpack lcd, and logging to a http server end point.I

I will build the project keeping these three projects separate. I haven't started anything yet except buying a Feather M4 because what the project is supposed to do requires floating point calculation.

The question is, it seems like using a single processor to service all three components, will.force me to compromise the primary function of the project. I'm just wondering if this becomes the case, is it common practice to move the UI to another processor and make it as another spi device?

How is it best to handle this situation?

sting
 
Posts: 167
Joined: Sun Jan 17, 2010 7:44 pm

Re: Common Practice

by adafruit_support_mike on Sun Dec 05, 2021 10:32 pm

Microcontollers are cheap, so exporting work to another one is perfectly reasonable these days.

That mindset is still relatively new though. Before the Arduino working with microcontrollers was expensive, and even during the early days of the Arduino a single board cost $20 or more. Moore's Law has driven performance up and prices down though, so now it's easy to find complete dev boards that cost less than $10.

For your use case, where trying to make a single microcontroller do everything forces unacceptable (or just unwanted) limits on functionality, splitting the load is a good choice.

adafruit_support_mike
 
Posts: 63921
Joined: Thu Feb 11, 2010 2:51 pm

Re: Common Practice

by User_UMjT7KxnxP8YN8 on Mon Dec 06, 2021 12:57 pm

While Mike is right, the ATSAMD51J19A processor on the Feather M4 Express board is a very capable processor, and well-designed software that uses the available features (interrupts, DMA) may be able to handle everything you need all on its own. You don't mention what "the function the project is supposed to do" is, what rate it must run at or the latency associated with any hardware involved so I can't say for sure, but I encourage you to do some analysis to determine whether it can all run on one board rather than assuming you'll need more hardware. I have not had a problem in over two years of routinely overclocking the ATSAMD51J19A to 200 MHz; you may want to factor that into your analysis.

Adding processors will increase the complexity of your system. You must design a robust method of coordinating their activities. Think about what will happen when one of your processors is tied up in a loop waiting for something to happen and the other tries to communicate with it. What if there's a bug on one processor that forces it to reboot? How will you recover if they get out of sync?

These are all solvable problems, but you're more likely to be successful if you think them through up front.

User_UMjT7KxnxP8YN8
 
Posts: 284
Joined: Tue Jul 17, 2018 1:28 pm

Re: Common Practice

by adafruit_support_bill on Mon Dec 06, 2021 1:15 pm

Unless your application is extremely compute intensive, chances are that it will be spending most of its CPU cycles waiting for something to happen. Whether or not you elect to offload some work on a separate processor, you typically still need to coordinate the various tasks while remaining responsive to events from all sources.

Techniques for achieving this are discussed in this series;

https://learn.adafruit.com/multi-taskin ... ino-part-1
https://learn.adafruit.com/multi-taskin ... ino-part-2
https://learn.adafruit.com/multi-taskin ... ino-part-3

adafruit_support_bill
 
Posts: 82782
Joined: Sat Feb 07, 2009 10:11 am

Re: Common Practice

by sting on Mon Dec 06, 2021 3:55 pm

I didn't write specifically about my project so I could get as general of a response as possible. It is something I have thought about doing for a long time.

Basically, If I understand correctly, with some clever programming and two pins along with the SPI pins, I can build a self contained subsystem that can get instructions from the master, send responses to the master in say a JSON format. The subsystem can use whatever other pins and do whatever it wants with the processor it uses. Sounds fun.

But, the project really isn't that complex and I probably need to learn a few things.

Basically I have a PID controller with a set point and a high and low value alarm. There are other probes that it has to manage, but they do not have the time constraint of the PID.

The user has a rotary decoder and can adjust either of the three parameters that they want at any time they want.

The project also writes the data to and reads data from a set of web api end point.

I haven't even soldered the M4 feather together yet, just getting my workbench setup, I'm old enough and my eyes are bad enough that I have a difficult time soldering so want to keep it to a minimum. This is sufficient reason to use the feather and feather wings.

I made this post because I was thinking about how to detect the roll of the rotary decoder between managing the temp of the PID +- 1 degree, and logging the data to the cloud, and not miss some turn of the decoder, this will be some learning on my part.

sting
 
Posts: 167
Joined: Sun Jan 17, 2010 7:44 pm

Re: Common Practice

by adafruit_support_bill on Mon Dec 06, 2021 4:37 pm

Rotary encoders are best handled with interrupts. Using an M4 processor, you could spin one with a power drill and barely notice the interrupt overhead. PJRC has a nice library for that. https://www.pjrc.com/teensy/td_libs_Encoder.html

PID for temperature control does require accurate timing, but is typically not all that time constrained. The thermal mass of most systems will give you pretty long lag-times. And a good PID implementation will use the actual time since the last iteration in its computation.

If you are looking to do a multiprocessor solution, 'common practice' is to separate functions such as user interface and database functionality from the data acquisition and control.

adafruit_support_bill
 
Posts: 82782
Joined: Sat Feb 07, 2009 10:11 am

Re: Common Practice

by sting on Tue Dec 07, 2021 12:13 pm

That all said, I still need more pins. i was going through the pinout for the feather M4 and the parts I need to use and I can't seem to find a way to multiplex enough lines to add the independent probes I want. I guess I could just leave them off?

I went with the feather to attempt to limit the amount of soldering I had to do. This does limit the number of pins I have available, but I am better at software then hardware.

So:
Airlift featherwing [13,12,11,10,rx,tx] 6 plus 3 SPI pins
Relay featherwing [9, 6] 2 pins
Backpack[scl, sda] 2 pins
Pt100 amplifier[5] 1 pin plus SPI pins
Switches[ao:mode switch, a1,a2: feature selection rotary switch: a3,a4: feature value rotary switch] 5 pins

Then: 9 + 2 + 2 + 1 + 5 = 19 leaving 2 pins and I need 4 for a multiplexer for the independent probes.

Is there something I'm not seeing?

sting
 
Posts: 167
Joined: Sun Jan 17, 2010 7:44 pm

Re: Common Practice

by adafruit_support_bill on Tue Dec 07, 2021 12:27 pm

You could use a Metro M4 Grand Central and the Airlift shield. Quite a bit bigger footprint - but plenty of pins.

adafruit_support_bill
 
Posts: 82782
Joined: Sat Feb 07, 2009 10:11 am

Re: Common Practice

by sting on Tue Dec 07, 2021 12:53 pm

Unfortunately, before I thought too much about it, I already bought the M4 feather, the airlift featherwing, and the relay featherwing.

So, unless I find another project to use these on, I am kind of stuck here. Unless it becomes too difficult.

One thing I have thought of, since the idea is to move UI to other processor, most of the critical aspects of using a separate processor are not as difficult as moving the PID to a separate processor.

sting
 
Posts: 167
Joined: Sun Jan 17, 2010 7:44 pm

Re: Common Practice

by adafruit_support_bill on Tue Dec 07, 2021 5:06 pm

UI and/or the WiFi would be good candidates to spin off.

adafruit_support_bill
 
Posts: 82782
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.