-3
\$\begingroup\$

I need to read certain physical parameters through the sensors and send them to the microcontroller and microcontroller should combine this information and send through rf transmitter. I can read all the analog parameters using ADC. There is PWM signal coming from the temperature sensor, I thought using interrupts, I can measure the signal length and get the info. The problem is sampling rate changes according to parameters. Some of them should be sampled with 2kHz some 500Hz and some of them 1Khz, also temperature sensor produces PWM in 1 second period. So how should I combine them and send properly and solve after receive?

Edit: I did not explain the question clearly enough. Problem is not about the acquisition. It is about, in which order, how often I should send the data. I don't want to lose information while sending data but also since sampling frequencies are different I should be able to differentiate which data is coming at receiver. My first idea is saving all data in 1 second period (the slowest data speed) and sending it once. Thus it will be in order. But now I guess sending each data when it is sampled and put some label while sending it is much better. So my main question is what is the common way to handle such a problem?

\$\endgroup\$

closed as unclear what you're asking by uint128_t, winny, Dmitry Grigoryev, brhans, PeterJ Jun 29 '18 at 11:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ This is a design question thus I can choose some unknowns like which microcontroller will be used. Consider communication speed, microcontroller clock frequency is adjustable. I have to use the RS485 protocol to communicate RF transmitter but information package how often i will send is something i should choose. If i dont loose any data i am fine. \$\endgroup\$ – Hüseyin GÖKTAŞ Jun 24 '18 at 23:26
  • \$\begingroup\$ What bothers me is when I sending data I can't simultaneously continue to record new data since it will be busy. If I use two microcontrollers one to send other to read and use a common ram as a buffer than how should i synchronize them. \$\endgroup\$ – Hüseyin GÖKTAŞ Jun 25 '18 at 0:25
  • \$\begingroup\$ @HüseyinGÖKTAŞ - the magic of interrupts allows your micro to appear to be doing more than one thing at a time. You probably don't need 2 micros. \$\endgroup\$ – brhans Jun 25 '18 at 0:43
  • \$\begingroup\$ is there one PWM signal and several analog signals? \$\endgroup\$ – Jasen Jun 25 '18 at 5:05
  • \$\begingroup\$ What will each type of measurement be used for after it has been received? \$\endgroup\$ – Nick Alexeev Jun 25 '18 at 6:13
0
\$\begingroup\$

The best way of reading PWM signal is by using timer-counter in input capture mode. You run your counter at high frequency and program it for external interrupt. When signal on a pin changes current counter value gets stored in the input capture register. All this is handled in hardware, so your program is free to do whatever else you need. You have to handle interrupts to acquire that value and to prepare next capture at the beginning of the pulse.

How exactly you connect those PWM signals depends on MCU. Some of them have only one input capture pin, so you have to use multiplexor IC and cycle it through your sensors. Or you can look for MCU with enough input capture pins for all your sensors.

Even if you have to use single input and multiplex sensors you do not need to worry about different PWM frequency. You simply run counter as fast as possible (not too fast to get overrun, though) and calculate actual duty in software according to input being sampled at the moment.

UPDATE:

If you asking about sending data, then it is completely different question.

First of all, you should clearly split data acquisition code from data transmission. Your sampling routines (especially ISRs) should not do any transmission, they should place all data into shared variables and forget about them.

Your transmission code then depends on the needs of your target recipient and available bandwidth only. For example, it can combine all data into one block and send this block every time. Slow data will be often sent unchanged, but the code will be very simple, on both transmitter and receiver.

Alternatively you can design your own protocol and send each parameter individually tagged by source ID. In this case you can send fast changing data more often. Ideally, the transmission frequency for each value will correspond to its acquisition rate, but since you've separated two layers your timing is flexible and you can finish previous transmission before sending next even if new data become available in the process.

In the end it is simple bandwidth calculation. Figure out how many bytes you can send every second given the transmission speed. Calculate how many blocks you can send and see if it gives you sufficient data rate per your requirements. If not, calculate individual data rates and see how many bytes you need to send per second (including tags) and sum them into total data volume. If it is still over transmission speed you are out of luck. If it is not you can go ahead and implement interleaved protocol.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.