I have a C++ app running on an Arduino Nano which has at its core a fast A/D read triggered by a pin interrupt. So, a shaft running at around 3000rpm has a sensor which triggers the interrupt every revolution. I then need to save the time this occurs and then do several hundred fast A/D converter reads of each of two other sensors, noting the time of each read. The values are saved for later use.
Sensing the interrupt is the only time critical job. Since I need better than one degree of resolution, the interrupt latency variation cannot exceed 28uS, which it appears I cannot achieve with the polled mechanism in B4R. Note, I can calibrate out the interrupt latency but I must have a latency variation of less than 28uS.
The A/D is read as fast as possible for many revolutions and the data stashed away. After enough revolutions there is data for every degree of position. If not it doesn't matter because it is all done again the next time the interrupt is enabled at which time the stale data is updated with new. A little bit of randomness goes a long way!!
This code works very well on an Arduino Nano, plodding along at 16MHz. It sends the data in packets on a USB link to a PC and a BC++ program does the number crunching and display. All very pretty but not very useful in a workshop environment.
I have rewritten the PC code in B4A to run an a mobile device and use WiFi/BT. This too works very well and is almost complete. It has the data structures to receive the data, but currently fills them with simulated data. Async streams looks like the best solution since there is some other data to be packaged as well as the raw sensor data.
I had planned to write the Arduino/ESP8266/ESP32/??? code in C++ but looking through the B4R documentation I seemed clear I could do this much more quickly with B4R - except for one problem....
How to manage the pin interrupt. It is a simple bit of code. The ISR just gets a system uS timer value and saves it somewhere that B4R can find it. The readings of the A/D can be handled by B4R as long as the timer can be read reliably and this does not need to happen in the ISR. No B4R code will be called from the ISR - I just need to know where B4R keeps its system timer and how to get a pin interrupt to work without annoying B4R.
So, after a lot of reading I am no closer to figuring this out than when I started. It is clear I need to use an object called pollers but I cannot work out how to use it. Reading source on GitHub is no help either. Some of the headers I searched for unsuccessfully for hours and without them I have no clue what some of the functions do, or how. Even experienced C++ programmers need a kickstart in the right direction to solve some problems.
Does anyone have any idea how I may go about this?
I could of course write it in C++ but that would mean figuring out how to duplicate the protocol used by B4A and AsyncStreams. Maybe this will be easier. I will take advice on this. B4R certainly makes the WiFi stuff easier to program.
I would also like to avoid a hardware solution. It's not difficult but makes the product more expensive and seems such a waste when I have perfectly good micro.
Sensing the interrupt is the only time critical job. Since I need better than one degree of resolution, the interrupt latency variation cannot exceed 28uS, which it appears I cannot achieve with the polled mechanism in B4R. Note, I can calibrate out the interrupt latency but I must have a latency variation of less than 28uS.
The A/D is read as fast as possible for many revolutions and the data stashed away. After enough revolutions there is data for every degree of position. If not it doesn't matter because it is all done again the next time the interrupt is enabled at which time the stale data is updated with new. A little bit of randomness goes a long way!!
This code works very well on an Arduino Nano, plodding along at 16MHz. It sends the data in packets on a USB link to a PC and a BC++ program does the number crunching and display. All very pretty but not very useful in a workshop environment.
I have rewritten the PC code in B4A to run an a mobile device and use WiFi/BT. This too works very well and is almost complete. It has the data structures to receive the data, but currently fills them with simulated data. Async streams looks like the best solution since there is some other data to be packaged as well as the raw sensor data.
I had planned to write the Arduino/ESP8266/ESP32/??? code in C++ but looking through the B4R documentation I seemed clear I could do this much more quickly with B4R - except for one problem....
How to manage the pin interrupt. It is a simple bit of code. The ISR just gets a system uS timer value and saves it somewhere that B4R can find it. The readings of the A/D can be handled by B4R as long as the timer can be read reliably and this does not need to happen in the ISR. No B4R code will be called from the ISR - I just need to know where B4R keeps its system timer and how to get a pin interrupt to work without annoying B4R.
So, after a lot of reading I am no closer to figuring this out than when I started. It is clear I need to use an object called pollers but I cannot work out how to use it. Reading source on GitHub is no help either. Some of the headers I searched for unsuccessfully for hours and without them I have no clue what some of the functions do, or how. Even experienced C++ programmers need a kickstart in the right direction to solve some problems.
Does anyone have any idea how I may go about this?
I could of course write it in C++ but that would mean figuring out how to duplicate the protocol used by B4A and AsyncStreams. Maybe this will be easier. I will take advice on this. B4R certainly makes the WiFi stuff easier to program.
I would also like to avoid a hardware solution. It's not difficult but makes the product more expensive and seems such a waste when I have perfectly good micro.