• AVR Freaks

AnsweredHot!Distribute work in several microcontrollers?

Page: 12 > Showing page 1 of 2
Author
PSR_Fran
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/11 13:12:00
  • Location: 0
  • Status: offline
2020/01/24 09:29:22 (permalink)
0

Distribute work in several microcontrollers?

Good morning everyone, I have the following question:
I have a project in operation based on a PIC18F67k40 at 20MHz with inputs, outputs, I2C communication with an LCD and serial transmission through port 1 (send only). Now I need to receive data through serial port 2 (only receive) at 115000 with frames of different sizes and at any time. The frames can be short or as long as more than 100 characters and up to 40 lines in a row. I have the interrupt # int_rda2 that is responsible for analyzing the frames received in search of certain words to act on the state of a port ... the problem is that when the frames are very long the program stops many times to address the interruption and The IC2 bus that communicates with the LCD is corrupted and it is necessary to enter an "INIT" at the output of the interrupt to recover the LCD.
After fighting for some time I am considering the possibility of using an auxiliary pic only to analyze the serial receptions and send the positives (enable / disable) a port and leave the main PIC with the current tasks.
Is it the right solution? Can the PIC18F67k40 really with all the work?
Thank you
#1
Jim Nickerson
User 452
  • Total Posts : 6474
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 09:34:00 (permalink)
+1 (1)
maybe you could set a volatile global variable in the interrupt to reduce the time spent in the interrupt and store the frame data in a buffer and process the flag in the main code.
this presumes the main code can handle the request before the next data frame and you have enough storage for the message
#2
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 09:39:48 (permalink)
+2 (2)
Yes You Could Use More PICs, Or a Bigger PIC. Or as pointed out do not sit in the Interrupt for so long.
#3
PSR_Fran
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/11 13:12:00
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 09:48:28 (permalink)
0
Thanks for the answer ... the possibility of using a second smaller PIC doesn't worry me about design or price but ...
Can I use the internal oscillator for 115000 communications? ... so I would not have to incorporate a crystal for the second PIC
#4
Jerry Messina
Super Member
  • Total Posts : 460
  • Reward points : 0
  • Joined: 2003/11/07 12:35:12
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 09:48:54 (permalink)
+3 (3)
Or you could figure out why receiving characters on the uart is causing I2C corruption.
 
Unless the LCD has come sort of timeout it shouldn't care about the I2C timing.
 
#5
PSR_Fran
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/11 13:12:00
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 09:57:21 (permalink)
0
Not only is I2C problem, the whole system becomes more lazy ... the keyboard suffers delays, the ports take time to respond ... etc ... it does not compromise the operation but it is annoying and the responses are sometimes slow
#6
hexreader
Super Member
  • Total Posts : 1039
  • Reward points : 0
  • Joined: 2008/05/04 03:06:55
  • Location: England
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 10:02:02 (permalink)
+1 (1)
Why not run PIC18F67k40 at 64MHz?  You will get better than 3 times the throughput and only spend 1/3 the time in interrupt.
 

Experienced Hobbyist
#7
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 10:03:12 (permalink)
+1 (1)
http://ww1.microchip.com/downloads/en/DeviceDoc/PIC18(L)F67K40%20Data%20Sheet%2040001841D.pdf
Page 868 Figure 40-6 says the internal oscillator for 115000 will only work under limited conditions.
Other PICs have better internal oscillators.  (An many have worse).  Note to add in the Baud rate error in your error budget.
#8
PSR_Fran
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/11 13:12:00
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 10:18:03 (permalink)
0
Thank you all for the answer ... it is clear that this module is not suitable for this purpose. This is a board that is already 2 years old and now this need arose but I will use an auxiliary pic for this work ...
Thank you
#9
NKurzman
A Guy on the Net
  • Total Posts : 18266
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 10:52:48 (permalink)
+1 (1)
You could use a more suitible PIC that is Pin compatible.
It is even possible a PIC24 would fit if you need even more speed.
#10
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11577
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 11:02:12 (permalink)
+5 (5)
Spreading bad software across multiple processors is only going to make matters worse.
#11
NorthGuy
Super Member
  • Total Posts : 5917
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 12:12:56 (permalink)
+2 (2)
jtemples
Spreading bad software across multiple processors is only going to make matters worse.



Very true.
 
Instead, write more efficient code, move long processing from ISR to main, and run your PIC faster.
#12
ric
Super Member
  • Total Posts : 25592
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Distribute work in several microcontrollers? 2020/01/24 13:43:57 (permalink)
+1 (1)
Agree with the two previous replies.
Plainly the ISR code is too inefficient, and is taking up to 100% of your execution time.
Almost certainly it could be improved.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#13
mpgmike
Super Member
  • Total Posts : 365
  • Reward points : 0
  • Joined: 2014/01/23 17:27:06
  • Location: NJ
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 14:34:14 (permalink)
+1 (1)
First thought was to use DMA, but the K40 doesn't have it.  Second thought was to migrate to the K42 (for DMA), but it doesn't have sufficient pins.  Third thought (the one with a chance) is to write your ISR code in ASM to maximize time.  Like NKurzman said, 16-bit PICs can offer what you need.

I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
#14
Jerry Messina
Super Member
  • Total Posts : 460
  • Reward points : 0
  • Joined: 2003/11/07 12:35:12
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/24 17:26:53 (permalink)
+1 (1)
16-bit PICs can offer what you need...

But they won't re-write the (likely) poorly structured ISR.
 
You'll just end up with faster code that sucks.
 
#15
schlabs
New Member
  • Total Posts : 22
  • Reward points : 0
  • Joined: 2012/02/09 09:39:07
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/25 11:12:20 (permalink) ☼ Best Answerby PSR_Fran 2020/01/25 17:23:48
+1 (1)
Dear i do the same work a couple of times. I do this:
IRQ from usart:
-have a variable char rx232_irq_dt[100]
-have a variable char rx232_irq_len
-Every character is received and apended unless the received be \n or \r
-when \n or \r is received i copy rx232_irq_dt --> rx232_dt and variable with the lenght too
-prepare to continue receiving
 
INTO the main i do
while (1==1){
if( rx232_len>0) analysis function.
 
This works fine, but can leak if you send 2 or more streaming without time to analyse. In this case the goal is a structure of received frames. Or keep the data into the irq until previous frame was readed or discard the arriving packet until previous frame is procesed.
 
#16
ric
Super Member
  • Total Posts : 25592
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Distribute work in several microcontrollers? 2020/01/25 13:22:44 (permalink)
+2 (2)
Simpler just to do it right.
Implement a FIFO for all received characters, and do all your parsing in a non-interrupt outer loop.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#17
PSR_Fran
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/12/11 13:12:00
  • Location: 0
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/25 17:40:03 (permalink)
0
Thanks for the answer ... I tried two options.
1. As you indicated, I implemented a variable data [] with a counter that saves each character that enters until a 13 (line break) is detected and then analyzed outside the interruption. It works but many times they enter 40 or 50 lines in a row and the process slows down the entire system.
2. Another way I tried was: for example the word I need is "CAR" which has 3 characters (from 0 to 2). When the first interruption enters, it compares the received caranter with the position or of the searched word ... if, for example, "C" increases the counter ... when the second character arrives it is compared with the character 1 of the word ... if for example it is "E" as it does not match "A" of "CAR" I break the cycle and read the value of the counter ... in this case it would be 1 and it would not match 2 which is the value for the word "CAR" ... if the counter coincides, it will reach 2. In this way, not all frames are analyzed, only those that coincide as caractars enter. Nor in this case did I get an optimal result ... with so many interruptions it is so short the system is slow ...
I'm investigating if this device has some kind of buffer that stores full frames but I can't find anything ... I'm a little rusty with this type of programming
#18
ric
Super Member
  • Total Posts : 25592
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: Distribute work in several microcontrollers? 2020/01/25 18:13:55 (permalink)
+1 (1)
That's a description of what you think you're doing.
Without a glimpse at the real code, we can't comment how efficiently you are doing it.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#19
jtemples
عُضْوٌ جَدِيد
  • Total Posts : 11577
  • Reward points : 0
  • Joined: 2004/02/13 12:31:19
  • Location: Southern California
  • Status: offline
Re: Distribute work in several microcontrollers? 2020/01/25 18:59:20 (permalink)
0
You haven't provided detailed requirements for your project; we don't know what terms like "in a row"  mean.  Give specific timings and examples.  Explain exactly what processing is done to a "line", and how you determine when a "line" has been received.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2020 APG vNext Commercial Version 4.5