How to keep changing data on a single line in Terminal

wapo54001

Senior Member
I am running a loop in a program and three of the lines in the loop are SERTXD commands sending data to the terminal. I would like those data items to remain in a single location on the screen, one data item per line, in three lines on the terminal display rather than scrolling.

I think that I should be using a special control code function to clear the screen after the data is displayed as described in the Terminal Settings but I don't know how to make that happen. I assume I send a code from within the program via SERTXD? How to I format that? Help appreciated.
 

Buzby

Senior Member
See page 16 of the PE6 briefing document : https://picaxe.com/docs/pe6.pdf
It says there that 'Control characters can be optionally used to navigate about the receive box'.

Then look at all the posts I've made about the lack of this functionality.
Here's one : https://picaxeforum.co.uk/threads/bug-report-1-mar-2020-pe6-terminal-control-character-behaviour.31898/#post-342245

Because of these limitations I've used three other methods to view tabulated data.

One is to write the data to specific memory locations, then view in the 'Memory Panel'.
The second is to add a simulated LCD, then send control characters to that.
Third is to run on a real chip, then send serial to a proper terminal emulation, like Realterm ot Terra Term.

None of these is as convenient as having a properly working PE6 terminal, but I don't think we are ever going to see that. :(

Cheers,

Buzby
 

hippy

Technical Support
Staff member
I am running a loop in a program and three of the lines in the loop are SERTXD commands sending data to the terminal. I would like those data items to remain in a single location on the screen, one data item per line, in three lines on the terminal display rather than scrolling.
This may do what you want -
Rich (BB code):
For w0 = 0 To 10
  w1 = w0 * w0
  w2 = w1 * w1
  SerTxd($0C) ; Clear Screen
  SerTxd("w0", TAB, #w0, CR, LF)
  SerTxd("w1", TAB, #w1, CR, LF)
  SerTxd("w2", TAB, #w2, CR, LF)
Next
In the Terminal 'Settings' options you need to untick "Display non-ascii as hex" and tick "Special Control Code Functions - Clear Screen on FF [0C]".
 

wapo54001

Senior Member
This may do what you want -
Rich (BB code):
For w0 = 0 To 10
  w1 = w0 * w0
  w2 = w1 * w1
  SerTxd($0C) ; Clear Screen
  SerTxd("w0", TAB, #w0, CR, LF)
  SerTxd("w1", TAB, #w1, CR, LF)
  SerTxd("w2", TAB, #w2, CR, LF)
Next
In the Terminal 'Settings' options you need to untick "Display non-ascii as hex" and tick "Special Control Code Functions - Clear Screen on FF [0C]".
hippy, that works really well, thanks!

One thing, I had to add a PAUSE 500 at the end of the series of SerTxd commands because every five or so iterations of the loop the entire first line would be blank except for the last digit of the number. No idea why, but the PAUSE solved the problem and also it actually makes the screen easier to read.

And the use of TAB here was a great piece of info -- makes formatting and readability easier/better so easily.
 

Attachments

Last edited:

wapo54001

Senior Member
@hippy,

I'm a pretty happy camper. Using the terminal code you suggested I was finally able to see the numbers I needed to see in order to tweak the code you provided to give me the numbers I need. Your use of the "**" simplified everything and was able to just use Word values for all the calculations. The screen capture below shows these values:

1) percentage control pot at half rotation gives 508 count (to be converted to 50~100% range next)
2) percentage value to be used is recalculated to 766 (half of 50~100 range)
3) power supply nominal voltage 831 = 24V of 30V max range
4) calculated power supply voltage to force relay Mute 621 = 75% of 831

Code:
DO

SERTXD ($0C) 'clear the terminal screen to display values

'Set Threshold for Mute to Percentage of PS nominal

'read Percent-of-nominal set Pot 
READADC10 Percent_Pot, Percent_Value
Sertxd ("Percent Pot",TAB,TAB,#Percent_Value,13,10)

'convert pot 0~1023 count to 512~1023 (50%~100% of nominal for cutoff)
Percent_Value = Percent_Value / 2  + 512 '% of nominal to be used for cutoff
Sertxd ("Percent_Value",TAB,#Percent_Value,13,10)

'read PS voltage to determine nominal value
READADC10 PS_Read, PS_Nominal
Sertxd ("PS Nominal",TAB,TAB,#PS_Nominal,13,10)

'Calculate Cutoff Value (percentage of nominal)
Percent_Value = Percent_Value * 64
PS_MinSet = PS_Nominal ** Percent_Value
Sertxd ("PS Cutoff",TAB,TAB,#PS_MinSet,13,10)

pause 500
LOOP
 

Attachments

hippy

Technical Support
Staff member
READADC10 Percent_Pot, Percent_Value
Percent_Value = Percent_Value / 2 + 512
Percent_Value = Percent_Value * 64
You can maximise pot resolution while retaining the same value range by using -
Code:
Percent_Value = Percent_Value + 1024
Percent_Value = Percent_Value * 32
And can put that on one line to reduce code size, increase execution speed -
Code:
Percent_Value = Percent_Value + 1024 * 32
 

wapo54001

Senior Member
You can maximise pot resolution while retaining the same value range by using -
Code:
Percent_Value = Percent_Value + 1024
Percent_Value = Percent_Value * 32
And can put that on one line to reduce code size, increase execution speed -
Code:
Percent_Value = Percent_Value + 1024 * 32
I need the end result to be in the 0-1023 range and the above doesn't give me that, I think there's a division step missing?

Does this code below do the same thing or am I missing something? (Resulting number seems good, but . . . )

Code:
Percent_Value = Percent_Value * 32 + 32768 / 64 MAX 970
It doesn't have to be fast, but I need to understand it. :confused:

I added MAX 970 which is 95% of nominal since I can see problems happening if the shutdown voltage is the same as nominal voltage.
 

hippy

Technical Support
Staff member
I need the end result to be in the 0-1023 range and the above doesn't give me that, I think there's a division step missing?
No, it's more that you were doing a multiply which perhaps didn't need doing. Getting a 512 to 1023, 50% to 100%, value would just be -
Code:
Percent_Value = Percent_Value / 2 + 512
No need to multiply by 64. And to limit it to 95% -
Code:
Percent_Value = Percent_Value / 2 + 512 Max 970
It would probably be better if the pot reading, going from 0-1023, was translated to 0-460 before adding the 512 but we can return to that later.

It is quite hard to explain the maths because we are dealing with scaled numbers 0-1023, 0-65535, etc and percentages rather than real numbers and ratio, has a number of solutions with varying degrees of resolution accuracy, and overflow comes into play.

It's that overflow which really causes problems. We can't do -
Code:
READADC10 Percent_Pot, Percent_Value
Percent_Value = Percent_Value / 2 + 512 Max 970
cutoff = nominal * Percent_Value / 1023
One needs to divide by 65536 to allow the '**' operator to be used. And, if we have multiplied 1023 by 64 to get 65536 (ish) we need to multiply 'Percent_Value' by 64 to make the maths work so we are back to where we started -
Code:
READADC10 Percent_Pot, Percent_Value
Percent_Value = Percent_Value / 2 + 512 Max 970
Percent_Value = Percent_Value * 64
cutoff = nominal ** Percent_Value
So what value range 'Percent_Value' has depends where one looks at it. It starts as 0-1023, becomes 512-970, then 32768-62080.

But there's no real need to have the intermediate step; you can move the multiply up and go straight from 0-1023 to 32768-62080.

The way I look at it is, we have got to be able to calculate 'cutoff' without overflow, and the only easy way to do that is with 'cutoff = nominal ** Percent_Value'. That dictates what range value 'Percent_Value' has there, and it's then merely a matter of converting a 0-1023 pot input to suit that -
Code:
Percent_Value = Percent_Value / 2 + 512 Max 970
Percent_Value = Percent_Value * 64
 
Top