Skip to content

Conversation

@whitfijs-jw
Copy link

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:
(0.001 sec/trigger) * (1 trigger/ 6 degree) * (174 degrees / valve opening) --> 29ms valve open
PXL_20201217_201110126

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

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

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.

Jonathan Whitfield added 6 commits December 16, 2020 13:19
	- added skeleton of freertos project to run on an STM32F103, use of HAL library should make the project somewhat portable to other STM32 processors
	- added task for FreeValve control
	- TODO: added external interrupt driver and interface to crank trigger
	- added external interrupt driver
	- added TIM3 time base
	- fixed trigger count overrun
	- added calculation of intake/exhaust opening (doesn't allow for overlap now -- will need to expand to the full engine cycle later)
	- fixed some project related stuff for the MCU
	- small cleanup
	- added maps for the full 720 degree cycle
	- fixed some indexing issues in the hal trigger interrupt
	- TODO: add sync loss semaphore/event
	- added semaphores for sync loss and crank sync
@Neywiny
Copy link

Neywiny commented Dec 18, 2020

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.

@whitfijs-jw
Copy link
Author

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.

@Neywiny
Copy link

Neywiny commented Dec 18, 2020

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?

@whitfijs-jw
Copy link
Author

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.

@ricallinson
Copy link

Very cool. I've been thinking on how to test the code in a CI tool chain. This is a sweet approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants