Reputation: 11
Currently I need to do the feasibility of microcontroller, that is I need to receive 200 CAN messages within 2 sec and copy the content to UART buffer within 2 sec, which means all processing should be finished within 2 sec, I need to identify my microcontroller is able to do task or not, if not how to choose the right controller for my requirement, is there any calculations to identify the CPU load, if yes please help me to solve this issue.
Thanks in advance!
I have no idea to calculate
Upvotes: 0
Views: 98
Reputation: 93566
Both CAN and UART Comms are much slower than the CPU, so it is more question of software design and scheduling than processor performance. There are many ways you could get that wrong and fail to get the data throughput you require, but it would not be down to lack of processor performance.
You have not provided the data rate of the CAN bus, or the "message" length. I assume by "message" you mean CAN "frame", but while for CAN, that is 8 bytes, for CAN FD it can be up to 64 bytes. Furthermore, an application layer protocol may have messages spanning multiple frames. So the term "messages" is ambiguous here
Let's assume that by 200 messages in 2 seconds, you mean 200 x 8 byte frames, and that over the UART you are transferring only the data payload, and not the CAN addressing information or any other framing/protocol metadata. That is then (200 x 8) / 2 or 400 bytes/s. Hardly taxing for any UART.
Assuming that you use N,8,1 data frames on the UART, that would be 10 bits per byte transferred, so the UART bit rate needs to be greater than 400 x 10 or 4000 bits/s. Conventional baud rates above that for UARTS are 4800, 9600, 19200, 34800, 57600 and 115200.
Even if you are using 64 byte CAN FD frames, that would require a still moderate 32000 bit/s.
You would struggle to find an MCU "too slow" to sustain your rather moderate data throughput. Of more concern would be how you buffer and schedule the transfer, and the real-time requirements of the system receiving the UART data. That is how much latency between transmission of a CAN "message" and arrival of the UART data can the system sustain? For example are all 200 messages to be collated and transferred to the UART as one data burst, or should each message be transferred immediately as it arrives?
The solution also depends on how much other work the processor is doing, and the real-time requirements of that work. However, if you were to use DMA transfers for both incoming CAN frames and outgoing UART data, there could be minimal software overhead in this application, and at these low data rates, there would be minimal bus contention slowing down other tasks.
Even without DMA, an entirely software transfer solution would not be taxing in this case. I would however advise using interrupt driven buffered output for the serial data as new CAN frames will arrive asynchronously. You always want to be ready for new input, not busy trying to shovel out the previous input.
If you have other work to be done on the processor, then the CAN input should also be interrupt driven in any case. For complex systems you might employ an RTOS to better and more easily manage scheduling overall.
Upvotes: 2