Open whitfijs-jw opened 3 years ago
I'm confused on why you'd recommend any RTOS at all? All it needs to do is act as a counter IC routed to a comparator IC. It doesn't need multitasking or anything like that.
I'm confused on why you'd recommend any RTOS at all? All it needs to do is act as a counter IC routed to a comparator IC. It doesn't need multitasking or anything like that.
If you want to have any hope of doing anything other than controlling the valves you'll need to have other operations going on at the same time (logging, live updates to parameters, etc). While it can be done with conditionals/switch statements in the main loop; that can quickly become unwieldy for anything more than simple tasks and absolutely unmaintainable when things get complex.
Having worked with FreeRTOS in the past on the ESP32, doing a switch/case is a lot easier than creating tasks, managing stack sizes, having a task to control other tasks, etc. If this were the full ECU then maybe, but just for controlling valves?
I'm not sure what to tell you, FreeRTOS is about a simple as it gets for RTOS's. It allows for task prioritization and preemption so less important tasks like logging can be put off if more important things like the control of the valves needs more time. With a large main loop you can miss synchronization with an important interrupt if you're stuck in another part of the main loop dumping things to log.
Very cool. I've been thinking on how to test the code in a CI tool chain. This is a sweet approach.
I don't have any Arduino's laying around but wanted to play around with this. I use STM32's frequently for my job and this is an eclipse GNUARM project setup for a board similar to these guys:
https://www.ebay.com/itm/STM32F103RC8T6-STM32F103RC8T6-ARM-Cortesx-M3-Leaf-Maple-Mini-Module-for-STM32/311756084407
I have a Segger J-link that I use for programming and debugging, but SWD programmers are cheap and sometimes come with some of the offerings on ebay.
For a project like this I would probably use a M4/M7 core w/ a FPU so one doesn't have to be so careful when using floating point values. ALso, with increased processing capabilities there would be cycles left over other activities like logging. I haven't used an Arduino in a while, but it looks like there are some cortex-M based models available that would probably be more suitable to use for a project like this than an 8-bit AVR.
FreeRTOS probably isn't the best choice as well, but its free and common. The hall sensor interrupt is runs outside of the FreeRTOS context for now, but I'll add a binary semaphore later on to sync with the control task for things like logging, etc.
Configuration of the valve open/closed parameters can be done in include/tasks/FreeValveControl.hpp. As its set up now it won't be possible to have valve overlap as each of the valve maps only spans 360 degrees.
Pics from testing (apologies for bad quality). Yellow is the simualted trigger signal, purple is the exhaust valve signal, green is the intake valve signal.:
1Khz square wave to simulate the trigger wheel (~1000rpm with a 60 tooth wheel). Only the exhaust cycle is running here:![PXL_20201217_201110126](https://user-images.githubusercontent.com/58998493/102550165-faa55f00-4082-11eb-8131-a40a0d94526b.jpg)
(0.001 sec/trigger) (1 trigger/ 6 degree) (174 degrees / valve opening) --> 29ms valve open
10Khz square wave to simulate the trigger wheel (~10000rpm with a 60 tooth wheel) Only the exhaust cycle is running here: (0.0001 sec/trigger) (1 trigger/ 6 degree) (174 degrees / valve opening) --> 2.9ms valve open
![PXL_20201217_201133070](https://user-images.githubusercontent.com/58998493/102550522-9505a280-4083-11eb-9555-b96578ce8ba2.jpg)
10Khz square wave to simulate the trigger wheel (~10000rpm with a 60 tooth wheel). The missing tooth was simulated by just counting cycles: (0.0001 sec/trigger) (1 trigger/ 6 degree) (174 degrees / valve opening) --> 2.9ms valve open![PXL_20201217_201359737](https://user-images.githubusercontent.com/58998493/102550767-fe85b100-4083-11eb-8080-ae4ca4c2885d.jpg)
TL;DR: I don't have an arduino, but I have a bunch of STM32 boards. Not sure if you'd want to merge this effort in, I'm happy to maintain a separate repo for different targets.