View previous topic :: View next topic |
Author |
Message |
RAWWAR
Joined: 26 Nov 2014 Posts: 13
|
Posted: Wed Feb 21, 2018 8:52 pm Post subject: cursor control |
|
|
Hi,
I hope someone can help me with the following problem.
I have an extarnel pulse connected to INT1 of my NANO with the m328P processor.
Every second ( or more ) there is an interrupt and a byte is written on the screen at a location,
determined by the cursorcontrol routines. See the program below
And that seems to work. Well... allmost. Lets say out of every
100 times these routines are called, 99 work just fine: cursor moves
to the new position, variable is printed and cursor moves back.
However in 1 of 100 cases ( or so ), the cursor does not jump to the
right position. Instead it prints part of the escape sequence
as characters on the screen and the cursor does not move.
I tried this with the built in monitor and also with teraterm.
Both gave the same problem.
I tried different baudrates but that makes no difference.
I work with XP and bascom v 2.0.8.1
Has anyone programmed cursor control routines and recognizes this ?
Or does anyone see something strange in my program ?
BR, Rob
Code: | $regfile = "m328pdef.dat" 'we use the 328p
$crystal = 16000000
$baud = 115200
$hwstack = 32 'was 32
$swstack = 24 'was 24
$framesize = 24
Config Submode = New
Const Esc = &H1B
Sub Save_curs_pos
Print Chr(esc) ; "7";
End Sub
Sub Restore_curs_pos
Print Chr(esc) ; "8";
End Sub
Sub Goto_x_y
Print Chr(esc) ; "[" ; Y_pos ; ";" ; X_pos ; "H";
End Sub
Sub Clearscreen
Print Chr(esc) ; "[2J"; 'clear screen, cursor to position 0,0
End Sub
Dim A As Byte
Dim X_pos As Byte
Dim Y_pos As Byte
On Int1 Int_1_service
Config Int1 = Falling
Enable Int1
A = 100
Enable Interrupts
Call Clearscreen
Do
nop
nop
Loop
End
''
''De int. 1 is connected to an external source which gives pulses,
''adjustable from 1 to 100 Hz.
''
Sub Int_1_service()
Save_curs_pos
X_pos = 15 : Y_pos = 3 : Goto_x_y
Print A;
X_pos = 20 : Y_pos = 5 : Goto_x_y
Print A;
X_pos = 25 : Y_pos = 7 : Goto_x_y
Print A;
X_pos = 30 : Y_pos = 9 : Goto_x_y
Print A;
X_pos = 35 : Y_pos = 11 : Goto_x_y
Print A;
A = A + 1
If A = 0 Then A = 100
Restore_curs_pos
End Sub |
The pictures below show how it should be:
and how things go wrong:
(BASCOM-AVR version : 2.0.8.1 ) |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Wed Feb 21, 2018 9:20 pm Post subject: |
|
|
$hwstack needs to be higher, try something like 64 or even more. |
|
Back to top |
|
|
RAWWAR
Joined: 26 Nov 2014 Posts: 13
|
Posted: Wed Feb 21, 2018 9:40 pm Post subject: |
|
|
No idea what i am doing then, but I tried it right away. first 64, then 100, even 128. But no improvement.
thanks anyway,
Rob |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Feb 21, 2018 9:48 pm Post subject: |
|
|
you have an empty main loop so only ISR code is acting.
I would think there could not be a problem.
Can you log all data to a file? Then zip and post the file? _________________ Mark |
|
Back to top |
|
|
RAWWAR
Joined: 26 Nov 2014 Posts: 13
|
Posted: Wed Feb 21, 2018 10:32 pm Post subject: |
|
|
Hi,
here is the .zip with all the files
Regards,
Rob |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Wed Feb 21, 2018 10:47 pm Post subject: |
|
|
Isn't it something simple like baudrate error.
115K @ 16Mhz will give 2.08% error and that's on the edge. http://wormfood.net/avrbaudcalc.php
Try a lower baudrate, for example 19.2K with an error of 0.2%
Btw What usb convertor is on your nano board (bottom)? _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Wed Feb 21, 2018 11:04 pm Post subject: |
|
|
Evert wrote: | Try a lower baudrate, for example 19.2K with an error of 0.2% | He bangs out in worst case 44 chars * 10 bits * 100 Hz, equals 44kBaud, so better use a suitable baud rate crystal like 14.7456 MHz. For testing 19.2k may work.
Also it may help to read out the UART's U2X bit, as baud rate error is bigger with U2X=0. |
|
Back to top |
|
|
laborratte
Joined: 27 Jul 2005 Posts: 299 Location: Berlin
|
Posted: Wed Feb 21, 2018 11:14 pm Post subject: |
|
|
I talked about hardware stack, not software stack!
Simulation shows, that you are using 39 Byte of hardware stack, so so type $hwstack=40 at least. 64 is safe.
But indeed, as your programm does not use any software stack at all, this can not be the problem.
Assume you have a baudrate problem as pointed out or a hardware issue. |
|
Back to top |
|
|
RAWWAR
Joined: 26 Nov 2014 Posts: 13
|
Posted: Wed Feb 21, 2018 11:38 pm Post subject: |
|
|
I too was thinking about a baudrate issue.
Therefore I tried several baudrates, 38400 end 19200 because of
the lower error rate. However: not better. I even went as low as 1200 baud,
because according to the table this should give 0,0% error.
It looked promissing for a short while, but then again: errors. Besides, in that case
the clearscreen sub seem not to work.
The nano contains a CH340G. I also tried another nano board (same chip) however: the same problem.
Finally I tried sending long strings like "The quick brown fox...etc." and that gives no problem.
The idea of changing the xtall to 14.7456 or 18.432 MHz has occurred to me and I do have them,
however I wonder if the bootloader still works then ?
Rob |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 22, 2018 12:21 am Post subject: |
|
|
RAWWAR wrote: | however I wonder if the bootloader still works then ? |
Yes if the BL is recompiled, or the programmer's baud rate can be tweaked. |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Feb 22, 2018 1:20 am Post subject: |
|
|
With PuTTY ->Terminal ->Keyboard ->VT100+ and I have clear output of this code + arduino nano + my gen from above 10min where Bascom terminal indeed have problem. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Thu Feb 22, 2018 12:11 pm Post subject: |
|
|
Simulated within AVR-Studio, recorded and parsed the output for over 120 interrupts there can't be noticed any flaw within the created assembler-code.
As there is no, and with variable interrupt rate there can't be any serial-handshake to make sure the receiver got every char, the most likely reason for the shown issue are hiccups at the receiver's side, one char is swallowed and then things go wrong.
I would nonetheless try to massively increase baud-rate, as then it's less waiting in the ISR, while it does not put any extra load onto the controller. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu Feb 22, 2018 9:05 pm Post subject: |
|
|
Quote: | here is the .zip with all the files |
That is not what i meant. I mean the terminal log file which will show all the received data.
But when i read all replies i think it is a problem in the VT100 emulation of the terminal emulator.
Try some other emulators to make sure. _________________ Mark |
|
Back to top |
|
|
RAWWAR
Joined: 26 Nov 2014 Posts: 13
|
Posted: Thu Feb 22, 2018 10:38 pm Post subject: |
|
|
Hello All,
thanks for all the replies.
I wrote before that I had the same problem with teraterm, but that seems to be not true.
Since EDC said that there were no flaws using Putty but there were errors in Bascom,
I again connected a RS232 converter to the Txd pin and to the PC,using TERATERM and voilá:
not one cursor move missed.
As a test I applied 250 Hz to the interrupt input (In real application it will be not more then
1 pulse per second ) but OK... and it runs now for an hour or so at 115200 Baud. Not 1 error.
Therefore I conclude that, as Marc already wrote in his last post, it must be a problem
in the VT100 emulation of the terminal emulator in Bascom.
Regards,
Rob |
|
Back to top |
|
|
|