Issues merging FlexCAN, freertos, ADC

tuliperr

New member
Hello,
I'm not very experienced with embedded systems, and currently I'm working on a project that uses a Teensy 4.0 and the following 3 libraries:
https://github.com/tsandmann/freertos-teensy
https://github.com/pedvide/ADC/blob/master/ADC.h
https://github.com/tonton81/FlexCAN_T4

I am planning to move to a Teensy 4.1 but currently the one I have is broken so I am testing on the 4.0.

The isolated parts that seem to work so far are reading from 16 input values using both ADCs, and sending a message on the CAN bus.
I am trying to connect the two parts so I can propagate the input values on the CAN bus.

The ADC readings are implemented in a non-blocking way that uses an IntervalTimer to trigger a read of the first pin, and when the read completes, the ISR starts a read for the next pin, etc, until all pins are done. This runs on a xTaskCreate thread from freeRTOS.

When I first tried merging the two components of the project, I was getting issues when compiling the libraries, like HEX not being recognized as a macro, and constrain not being defined. After some workaround like replacing HEX with 16 and redefining constrain in the file where it was not found, I was able to get the code compiling, but when I upload it to the Teensy, the orange button keeps blinking and I get no serial output.

I am thinking this could be an issue arising from the ADC interrupt-based approach interfering with the interrupt handling from the CAN library, but I'm not super sure since I do not fully understand how interrupts are currently implemented in both libraries and what extra steps I would need to take to make them compatible.

Does anyone have experience with this or have any ideas on steps I could take to combine these?

Thanks in advance :)
 
No, so far I've been testing manually. I'm not super sure how to write test sketches since the code, at least the ADC parts, rely pretty heavily on sensor input and all I've been doing so far is cycling through reads. I'm not super sure how to break it down further into testable components either. Do you have suggestions on this?
 
Sure, for the ADC, start by doing what you want to do without FreeRTOS. When you have that working, try to adapt it to FreeRTOS. When you get that far, at least you'll know that you can, in fact, use FreeRTOS as you're trying to do.
 
This may be a silly question but why are you using freeRTOS? Reading an ADC and outputting the values on CAN doesn't require an RTOS.
If this is a learning experience or required for some course then fair enough but if you are simply trying to achieve a goal then adding in the RTOS is adding a lot of extra complexity for no meaningful benefit.
 
Back
Top