Just done a quick test with esp32 and ToString$(.x) takes about 2uS for .x = 1234.
Did you mean FloatToString$ - this took ~8uS (this on an esp32?)
If you are using something slower - say an Arduino - then if you want to use floats then multiply by 100 (10 / 1000 depending how many digits accuracy) and use ToString$ (avoid fp arithmetic)b Use the least number of digits (and smallest variable type) that you can get away with.
Writing my own fixed number of digits ToStr - takes 830nS for 4 digits
Martin
PIC18F25K22 UART ERROR
-
- Valued Contributor
- Posts: 1342
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 126 times
- Been thanked: 667 times
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
Very helpful info.
I think the only sensor that used floating point was the 6050 and it may be possible to use integers, or at least limit the decimal places for those readings.
Even with the PIC running a lot slower than the ESP, the mS results do at first look seem quite odd.
Regards
Very helpful info.
I think the only sensor that used floating point was the 6050 and it may be possible to use integers, or at least limit the decimal places for those readings.
Even with the PIC running a lot slower than the ESP, the mS results do at first look seem quite odd.
Regards
-
- Posts: 119
- Joined: Tue Dec 13, 2022 9:04 pm
- Has thanked: 31 times
- Been thanked: 2 times
Re: PIC18F25K22 UART ERROR
Hichipfryer27 wrote: ↑Sun Mar 03, 2024 7:50 amHi
Floating point calculations can be quite resource heavy on an 8-bit. The 25K22 has an internal oscillator that runs at 16MHz and you can also use the 4 x PLL to up the speed to 64MHz, thereby improving speed by a factor of four.
The peripherals will still take time to obtain data, but at least calculations etc will improve.
Regards
I use 4xPLL to up the speed to 64MHz, so the frequency of iteration at Send Loop is now about 70/sec, near to my goal...I would like to know what is the frequency of sending Data( MMA8452 + MAX30100 ) from receiver to UART..How can i measure that in receiver ?
Regards
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
First I'd follow Martins's suggestion (as always) regarding the calculations. Do you really need (for example) 123.xyz if 123.x could do instead? Reducing these times will result in significant savings.
Increase comms speeds to all sensors / modules to maximum that allows reliable communications (400KHz / 115200 baud).
The time to actually transmit between devices is unfortunately out of your control as that relies on the connecting infrastructure (e.g. your WiFi router and how "busy" it is), However if on your WiFi LAN you can measure this. On your Tx device set a pin just before you transmit. On your Rx decice set a pin as first action in your Rx Interrupt routine. Trigger a scope / analyser on Tx and measure between pins.
Sorry to be brief.
Regards
First I'd follow Martins's suggestion (as always) regarding the calculations. Do you really need (for example) 123.xyz if 123.x could do instead? Reducing these times will result in significant savings.
Increase comms speeds to all sensors / modules to maximum that allows reliable communications (400KHz / 115200 baud).
The time to actually transmit between devices is unfortunately out of your control as that relies on the connecting infrastructure (e.g. your WiFi router and how "busy" it is), However if on your WiFi LAN you can measure this. On your Tx device set a pin just before you transmit. On your Rx decice set a pin as first action in your Rx Interrupt routine. Trigger a scope / analyser on Tx and measure between pins.
Sorry to be brief.
Regards
-
- Posts: 119
- Joined: Tue Dec 13, 2022 9:04 pm
- Has thanked: 31 times
- Been thanked: 2 times
Re: PIC18F25K22 UART ERROR
Continuing some improvements on project I'll try to convert 2 sensors as wireless ..
Finally I select NRF24L01 transceiver to make 2 sensors wireless.
A. FSR SENSOR
1. FSR sensor with Analog out, is connected to A2 Analog IN on a PIC12F1822 that connected to NRF24L01 module (SPI). That works as transmitter.
2. Another PIC12F1822 is connected to a second NRF24L01 module(SPI) that works as receiver. Analog out at pin A0.
B. MAX30100 heart rate SENSOR
1. MAX30100 module is connected to PIC16F1847 (I2C IN ), and that MCU is connected with NRF24L01 module (SPI)..That works as transmitter.
2. Another PIC16F1847 is connected to a second NRF24L01 module (SPI), and received data from MAX30100 are at pins B2, B5 ( I2C). That works as receiver.
I made some demo codes for 2 pairs to make some tests . I have no sensors data to receivers..I was checked hardware for errors , I was changed NRF, but I have no data..Any idea about errors in below codes?
Many thanks
Basil
Finally I select NRF24L01 transceiver to make 2 sensors wireless.
A. FSR SENSOR
1. FSR sensor with Analog out, is connected to A2 Analog IN on a PIC12F1822 that connected to NRF24L01 module (SPI). That works as transmitter.
2. Another PIC12F1822 is connected to a second NRF24L01 module(SPI) that works as receiver. Analog out at pin A0.
B. MAX30100 heart rate SENSOR
1. MAX30100 module is connected to PIC16F1847 (I2C IN ), and that MCU is connected with NRF24L01 module (SPI)..That works as transmitter.
2. Another PIC16F1847 is connected to a second NRF24L01 module (SPI), and received data from MAX30100 are at pins B2, B5 ( I2C). That works as receiver.
I made some demo codes for 2 pairs to make some tests . I have no sensors data to receivers..I was checked hardware for errors , I was changed NRF, but I have no data..Any idea about errors in below codes?
Many thanks
Basil
- Attachments
-
- DEMO CODES-WIRELESS SENSORS.zip
- (13.26 KiB) Downloaded 248 times
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
I'll try to have a look at the weekend. Internet issues are hindering access to the forum.
Regards
I'll try to have a look at the weekend. Internet issues are hindering access to the forum.
Regards
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
Just a quick PS to above, I have a good idea of what you are aiming for but can't really look at things until the weekend.
I would start by getting the two RF modules to communicate, maybe by following the WiKi examples first. Once I knew I had comms I'd then try to incorporate other modules / sensors etc.
Regards
Just a quick PS to above, I have a good idea of what you are aiming for but can't really look at things until the weekend.
I would start by getting the two RF modules to communicate, maybe by following the WiKi examples first. Once I knew I had comms I'd then try to incorporate other modules / sensors etc.
Regards
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
Not had a chance to look at your code yet but I should have a couple of the transceiver modules somewhere. If I remember correctly, most problems with these type of modules are related to very poor build quality.
Adding an antenna appears to help whilst in other cases adding in capacitors improves performance. It seems you get what you pay for with these. Cheap doesn't mean better.
My modules have an SMA connector with a little antenna and again if I remember correctly worked fine in my "evil lab" but I've not done any range tests or anything. I can't remember when or why I got them but guess it was for some test or another. Doubt if I have still have any code as I can't really remember much other than they "worked" for whatever it was.
However if I can get them talking again it may help with your project.
Regards
Not had a chance to look at your code yet but I should have a couple of the transceiver modules somewhere. If I remember correctly, most problems with these type of modules are related to very poor build quality.
Adding an antenna appears to help whilst in other cases adding in capacitors improves performance. It seems you get what you pay for with these. Cheap doesn't mean better.
My modules have an SMA connector with a little antenna and again if I remember correctly worked fine in my "evil lab" but I've not done any range tests or anything. I can't remember when or why I got them but guess it was for some test or another. Doubt if I have still have any code as I can't really remember much other than they "worked" for whatever it was.
However if I can get them talking again it may help with your project.
Regards
-
- Valued Contributor
- Posts: 1434
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 337 times
- Been thanked: 497 times
Re: PIC18F25K22 UART ERROR
Hi
Just had a quick look at W_SPI_to_I2C chart.
This has the nRF24L01,a SPI Master, and two I2C devices. However it appears you are trying to share pins that use differing protocols.
nRF uses a software SPI on pins :-
MOSI = B2
MISO = B1
CLK = B4
CS/SS = A5
CE = A3
SPI Master is using software SPI on :-
MOSI = A6
MISO = B1
CLK = B4
CS/CE = A5
Not sure why this component is necessary nor why they run at differing clock speeds and MOSI, sharing the same CS/CE. Maybe I'm missing something? You also have the MOSI and I2C SDA sharing pin B2. I think you might be over complicating things.
I think it may be better to get this project running in stages, with the first being getting the two microcontrollers talking over the RF link, then adding in the sensors. Hopefully in the next few days I can dig out my modules and get them talking.
Regards
Just had a quick look at W_SPI_to_I2C chart.
This has the nRF24L01,a SPI Master, and two I2C devices. However it appears you are trying to share pins that use differing protocols.
nRF uses a software SPI on pins :-
MOSI = B2
MISO = B1
CLK = B4
CS/SS = A5
CE = A3
SPI Master is using software SPI on :-
MOSI = A6
MISO = B1
CLK = B4
CS/CE = A5
Not sure why this component is necessary nor why they run at differing clock speeds and MOSI, sharing the same CS/CE. Maybe I'm missing something? You also have the MOSI and I2C SDA sharing pin B2. I think you might be over complicating things.
I think it may be better to get this project running in stages, with the first being getting the two microcontrollers talking over the RF link, then adding in the sensors. Hopefully in the next few days I can dig out my modules and get them talking.
Regards
-
- Posts: 119
- Joined: Tue Dec 13, 2022 9:04 pm
- Has thanked: 31 times
- Been thanked: 2 times
Re: PIC18F25K22 UART ERROR
Hi,
I was checked connections between 4 pairs according some examples from wiki for NRF24L01...
I send you schematics as from them I was made hardware for transmitters and receiver...transmitters for FSR and MAX30100 sensors are mobile , receiver was made in one small PCB that include PIC18F46K22 to get received data from sensors, and then send to ESP8266 as the previous project with wired sensors ..So, in transmitter PCB of previous project , I was added 2 pairs of NRF24L01 with PIC, to make sensors wireless..
I would like if it possible to check codes for errors...In simulation seems to works well , but In tests on hardware I can get data on receiver PCB.
Regards
Basil
I was checked connections between 4 pairs according some examples from wiki for NRF24L01...
I send you schematics as from them I was made hardware for transmitters and receiver...transmitters for FSR and MAX30100 sensors are mobile , receiver was made in one small PCB that include PIC18F46K22 to get received data from sensors, and then send to ESP8266 as the previous project with wired sensors ..So, in transmitter PCB of previous project , I was added 2 pairs of NRF24L01 with PIC, to make sensors wireless..
I would like if it possible to check codes for errors...In simulation seems to works well , but In tests on hardware I can get data on receiver PCB.
Regards
Basil
- Attachments
-
- 17245875305754395708514397543327.jpg (77.83 KiB) Viewed 4272 times
-
- 17245874839206356394531364250448.jpg (76.18 KiB) Viewed 4272 times