PIC18F25K22 UART ERROR

For general Flowcode discussion that does not belong in the other sections.
SILVESTROS
Posts: 90
http://meble-kuchenne.info.pl
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi
Many thanks for info..I'll make some tests in hardware ..Is there a way to count the sample rate (samples/sec), maybe with a variable in receive loop ?
regards
Basil

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

Maybe in the transmitter, when you collect data, perhaps have dummy data that increments? I think you have six variables you transmit so maybe have six variables such as V1/V2/V3/V4/V5/V6 and in each iteration of your loop increment (V1=V1+1 V2=V2+1 etc)

Make sure the dummy variables are of the same type as you will use for real and that the length of the string is roughly the same as what you will actually send.

So each iteration of the loop will send six variable, for example 1,1,1,1,1,1 then 2,2,2,2,2,2 then 3,3,3,3,3,3 etc

At the receiver that is what you should receive in Excel

1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
etc

If you are going too fast you will start to get corrupted data which could mean a total loss or just garbage coming into Excel. If all is going well each row should be one value higher than the previous, containing all six values. Anything else means too fast.

Hope this helps.

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi
After some tests , max. sampling rate is 15/sec..in transmitter, I was set a pin on/off with delay in send loop (main) 1ms to measure the period of the loop with an oscilloscope...It was 36ms , so f sampling=27/sec..Delays at send loop(main) and Esp_Send are 7ms..Below that data are not send...
Is there any other way to increase sampling rate?..maybe to change the way that we get data in Get_Data?
regards
Basil

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

No real access to hardware just now so I can't test and sorry to be brief.

In the transmitter we have two delays. The first was in the Main loop and was specifically to control how many times per second / minute / whatever the loop ran. I think you have adjusted that and from the above you get a maximum of 15 loops per second.

Remember though that there is a second loop in the Macro that actually sends the data. As part of the process we connect to the server and tell it that we are about to send it some data and how many bytes to expect. We need to allow time for the server to respond before we actually send our data and it responds with a " > " prompt (if viewed in a terminal program). We don't actually "test" for the reception of this prompt before we send data, we just add in a delay so that the program waits long enough for the server to respond before actually sending the data.

You could try reducing this delay. On a local network the time between informing the server we are going to send something and it replying will be far faster than over the internet. I suspect this will be a limiting factor. If I remember correctly you are using an 8266 module, so increase the Baud to the module to maximum (115200) thereby reducing the time taken to "talk" to each other.

Next, your sensor modules will have a maximum polling frequency. Use the maximum speed you can to talk to them too. Maybe just do a test where you loop gathering data, again toggling your pin, as a check to see maximum?

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi
I was made some changes to properties of sensors so the transmitter sends data with 2 delays at 1ms. But iteration period at send loop (MAIN) was only about 35ms, so f=28/sec.. My goal is near to 80/sec, so total period of 2 macros must be about 12ms..
Using some pins, I set H/L to parts of macros (Get_Data, ESP_Send) to measure periods and find the following..
1..ESP_Send
WLAN_ESP8266 : SendString ("AT+CIPSend=",0)
WLAN_ESP8266 : SendString (Len_Str, 1)
period ...1.2ms

WLAN_ESP8266 : SendString ( Data , 0 )
period ...2.3ms

2..Get_Data ( I was removed force sensor )
MMA8452 : Update XYZ Data
MMA8452 : Collect XYZ Data (0)
MMA8452 : Collect XYZ Data (1)
MMA8452 : Collect XYZ Data (2)
period ...1.7ms

MAX30100 : Update
MAX30100 : Read IR
MAX30100 : Read Red
period ...3ms

x = ToString (xaxis)
y = ToString (yaxis)
z = ToString (zaxis)
hr = ToString (hrate)
ox = ToString (oxm)
period...20ms

Data = ""
Data = Data + x
Data = Data + ","
Data = Data + y
Data = Data + ","
Data = Data + z
Data = Data + ","
Data = Data + hr
Data = Data + ","
Data = Data + ox
Data = Data + ","
Data = Data + "/r/n "
Length = Length $ (Data)
Len_Str = ToString$(Length)
period...7ms

As we see, ESP_Send macro has total period 3,5ms. The longer is Get_Data with 31,7ms. Most of the time they spend the two last parts ..any idea on how to reduce that time ,especially at those two parts ?

regards
Basil

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

Good in getting the esp "sends" down. That could probably be improved further by looking for a response (any, with a timeout) instead of the delay.

I'm really surprised at how long the calculations are taking though.

I've very limited access to things just now but when I get a chance I'll try a couple of tests.

Regards

SILVESTROS
Posts: 90
Joined: Tue Dec 13, 2022 9:04 pm
Has thanked: 24 times
Been thanked: 1 time

Re: PIC18F25K22 UART ERROR

Post by SILVESTROS »

Hi

Further analysis of last 2 parts of macro "Get_Data" shows the following..

3 calculations x,y,z to string....period...11.2ms
2 calculations hr,ox to string....period...6.8ms
after some corrections for that part , total period is 18ms

11 calculations Data = Data + xx ....period...3.2ms
2 calculations Length = Length$(Data)
Len_Str = ToString$(Length)....period...3.5ms
total period for that part is 6.7ms

The execution time for calculation is too long, given that the instruction execution time for an 8bit MCU with 16MHZ clock is no more than 2μs in most cases..I'll check the calculation time in another project .

regards
Basil

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

I agree that something doesn't seem right as those times seem far too long. When I get a chance I'll run a couple of tests too.

Regards

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: PIC18F25K22 UART ERROR

Post by chipfryer27 »

Hi

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

mnfisher
Valued Contributor
Posts: 953
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 507 times

Re: PIC18F25K22 UART ERROR

Post by mnfisher »

ToString handles a lot of cases.

Might be worth creating a simple NumToStr that is quicker - if the data allows. For example, output all the numbers as 3 digits (only allows 0..999) with leading 0s if necessary.

Martin

Post Reply