View Full Version : how to control the incoming data?
zx81sp
- 28th April 2009, 09:32
How can I control when data is incoming? I have a pcb with Max232 and it sends/receive data, this is a portion of the code:
'Waits 200ms until 129 is received, then store next byte in I, if timeout jump to M2
SERIN SERIAL_IN,BPS,200,M2,[129],I
This works ok but I loose 200ms waiting for data and that PCB needs to control more things, so it becomes slooooooooow. If I change it to 100ms it loose commands, if I use 500ms it works perfect, but then the rest of the code has no time to do its job.
I can't use interrupts because the PCB uses PORTB.7 for SERIAL_IN.
I've tried a "stupid way" (and obviosly it does not works):
if SERIAL_IN=0 then 'something is changin in the RX PORT
'Waits 200ms until 129 is received, then store next byte in I, if timeout jump to M2
SERIN SERIAL_IN,BPS,200,M2,[129],I
endif
but the data received usually is corrupted. Then I've tried to repeat the commands from the PC (129-22-129-22) but also does not works ok.
Any idea of how can I make this works better?
Regards
Ioannis
- 28th April 2009, 09:57
Yes there is an excellent way and is called DT-Instant Interrupts!
Ioannis
zx81sp
- 28th April 2009, 14:42
Yes there is an excellent way and is called DT-Instant Interrupts!
Ioannis
But that way is intended to use the INT port. I'm using a PCB with 16F628A, INT=RB0, and the port I must observe is RB7, so I can not see how to use Darrel's way :confused:
Ioannis
- 28th April 2009, 20:07
It seems you do not read, or not read carefully.
Your PIC has USART.
USART has Interrupt that has nothing to do with PORTB.0 INT interrupt.
Darrels Interrupts cover all possible Interrupt sources of a PIC. You just have to enable th appropriate interrupt.
Example follows. On a terminal press key "1" to see the effect. (Not tested...)
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
'::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX_INT, _Get_char, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
'::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::
@ INT_ENABLE RX_INT ; enable UART RX interrupt
loop:
if mybyte="1" then
hserout "I got it!"
mybyte=0
endif
goto loop
'---[USART RX Interrupt handler]----------------------------------------------------
Get_char:
hserin 100,noreceived,[mybyte] 'Get byte
noreceived: 'or if timeout return
@ INT_RETURN
Ioannis
P.S. As a homework do set the USART parameters with DEFINE's to 9600
zx81sp
- 28th April 2009, 22:16
It seems you do not read, or not read carefully.
Your PIC has USART.
USART has Interrupt that has nothing to do with PORTB.0 INT interrupt.
Darrels Interrupts cover all possible Interrupt sources of a PIC. You just have to enable th appropriate interrupt.
I'm not english spoken, but USART is on RB.1 (RX), I can not use that PIN, just RB.6 for incoming data, and RB.6 as far as I know, can not be managed with interrupts.
It's a finished PCB and I'm trying to add some features, but can't change the hardware, otherwise this problem will be very easy to solve, still don't know hoy can DT-Interrupts can be applied here :confused:
Regards
Luckyborg
- 28th April 2009, 22:47
i don' know if your application will allow for it, but you can try adding polling throughout your code to have smaller wait times during the check and look for and use the wait command in serin2
main:
... normal stuff
gosub get_data
... more normal stuff
gosub get_data
...
more normal stuff
goto main
get_data:
serin2 Serial_IN, 84, 50, nodata, [wait (129), x]
nodata:
return
If you can adjust your transmitting device add a bunch of dummy spaces before the transmission so if you miss 1 or 2 no big deal, you weren't going to use them anyway. I''ve used something similar in the past.
Ioannis
- 29th April 2009, 07:29
If it is one off then I suggest to re-design your PCB. You won't have satisfactory results whatever you do besides the Interrupts generated by the USART.
There may be plenty of ideas, but will not respond fast enough.
Ioannis
mister_e
- 29th April 2009, 17:38
RB6 can use Interrupt on change, so yes you can use it.
It show one problem though, it will detect the Start-Bit... so there's big chance that SERIN/DEBUGIN/SERIN2 will not work as expected. But you could roll your own serial routine which will ignore the start-bit. This will work or not depending of your Baudrate and if you go on a ASM or PBP interrupt + home made serial routine. When using Darrel's instant interrupt with PBP type, it need some time to save/restore PBP systems var. Have a look at the following
http://darreltaylor.com/DT_INTS-14/kudos.html
If you create your own PC software, OR if you create your own transmitter with another PIC... then it open a few other possibilities.
But yeah, when at all possible, I prefer the USART interrupt as well.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.