UARTsircs prog
I am using Jon's program as a starting point for discussion. What I tried to do is add a second UART to the program; I basically added the same code that was used for the first UART, but changed some values like the TX and RX pins. Of course the program did not run as expected, but I was surprised that the sircs section of code worked as expected. So, that means that the interrupt was still in tact, from a timming perspective.
So, the problem is in how the UART code is implemented, any ideas as to what should be looked at first. It seemed to me that it should be as simple as changing the pin assignment, in the code to TX1, RX1, TX2, and RX2. Now the program goes through the code for UART1 and UART2, and it should work.
I looked at the Scenix DUAL UART code as a reference, but of course it's in asm, and it discussed some things like threading. Now I am not sure as to how you could achieve that using SX/B. I am already starting to run into variable space problems, and the code size is still very small, I am using an SX52 proto board. Any ideas or comments.
Thanks
Ray
So, the problem is in how the UART code is implemented, any ideas as to what should be looked at first. It seemed to me that it should be as simple as changing the pin assignment, in the code to TX1, RX1, TX2, and RX2. Now the program goes through the code for UART1 and UART2, and it should work.
I looked at the Scenix DUAL UART code as a reference, but of course it's in asm, and it discussed some things like threading. Now I am not sure as to how you could achieve that using SX/B. I am already starting to run into variable space problems, and the code size is still very small, I am using an SX52 proto board. Any ideas or comments.
Thanks
Ray
Comments
Post Edited (JonnyMac) : 4/2/2007 2:17:24 PM GMT
The only thing that I did was change the device to SX52, OSCXT2, BOR42 in the UART_SIRCS.SXB program. Anybody else having this problem, or do I have to do some other changes to the program to make it work on an SX52 chip. Any ideas or comments.
Thanks
Ray·
'
' Device Settings
'
DEVICE········· SX52, OSCHS2, BOR42
FREQ··········· 50_000_000
ID············· "MyBot"
'
' IO Pins
'
RX············· PIN···· Rd.7 INPUT
TX············· PIN···· Rd.6 OUTPUT
IR············· PIN···· RB.0 INPUT
'
' Constants
'
' Dividers for ISR UART
' -- values set for 4.34 uS interrupt rate
Baud2400······· CON···· 96
Baud4800······· CON···· 48
Baud9600······· CON···· 24
Baud19K2······· CON···· 12
Baud38K4······· CON···· 6
Baud57K6······· CON···· 4
Baud1x0········ CON···· Baud57K6··············· ' 1 bit period (ISR counts)
Baud1x5········ CON···· Baud1x0 * 3 / 2········ ' 1.5 bit periods
Yes············ CON···· 1
No············· CON···· 0
'
' Variables
'
flags·········· VAR···· Byte
rxReady········ VAR···· flags.0················ ' serial byte avialable
rxCmd·········· VAR···· flags.1················ ' receiving IR command
rxBit·········· VAR···· flags.2················ ' measuring bit width?
hasKey········· VAR···· flags.3················ ' IR cmd code available
idx············ VAR···· Byte
tix············ VAR···· Word··················· ' (ISR) for DELAY_MS
'serial········· VAR···· Byte (16)·············· ' bank for serial vars
'txCount········ VAR···· serial(0)
'txDivide······· VAR···· serial(1)
'txLo··········· VAR···· serial(2)
'txHi··········· VAR···· serial(3)
'rxCount········ VAR···· serial(4)
'rxDivide······· VAR···· serial(5)
'rxByte········· VAR···· serial(6)
txCount· var Byte
txDivide· var Byte
txLO· var Byte
txHi· var Byte
rxCount var Byte
rxDivide var Byte
rxByte var Byte
'sircs·········· VAR···· Byte (16)·············· ' bank for SIRCS vars
'sircsTix······· VAR···· sircs(0)··············· ' ISR divider
'cmdWork_LSB···· VAR···· sircs(1)··············· ' work space for cmd
'cmdWork_MSB···· VAR···· sircs(2)
'bitCount······· VAR···· sircs(3)··············· ' track bits received
'bitWidth······· VAR···· sircs(4)··············· ' measure bit width
'cmdCode_LSB···· VAR···· sircs(5)··············· ' key code
'cmdCode_MSB···· VAR···· sircs(6)··············· ' device code
'keyCode········ VAR···· sircs(5)
'devCode········ VAR···· sircs(6)
sircsTix· var Byte
cmdWork_LSB· var Byte
cmdWork_MSB var Byte
bitCount var Byte
bitWidth var Byte
cmdCode_LSB var Byte
cmdCode_MSB var Byte
keyCode var Byte
devCode var Byte
tmpB1·········· VAR···· Byte··················· ' work vars
tmpW1·········· VAR···· Word
The SX52 is different from the SX28 and the program may require some updates to make it work on the new platform, especially with manual memory management as is required when using the ISR stuff.
The SXB compiler flatened out the programming space, but you still have to deal with variable space limitations. So if you have to deal with those limitations, then it sounds to me like you have to go back to the 'bank' method of programming. I think I am going backwards here. Does anybody know, in an SX52 chip, how much programming and variable space you get in a bank. Since it is different than an SX28, that would be good to know. Any other tidbits of info would come in handy for the SX52.
In the Help file under Reference | Definitions | Variables you should find a table describing the variable space differences between the different SX versions.
I recommend that you define your UART variables in the following way:
Then change your variable references in each subroutine accordingly. What this should do is provide each UART with its own set of independent variables that are all in the same 16-byte array (or BANK).
I have not tested this but hopefully it will start you in the right direction.
- Sparks
Many SX/B commands will work fine with array variables. A few (notably an index into an array) will not.
You do not need to put every variable into an array. Since the UART variables were initially part of an array, they should be happy in an array. Why change them? And if the SIRCS variables do not work as part of an array, why try to change them?
If you followed my previous recommendation, the UART should have 12 variables as part of the Serial VAR BYTE(16) array. (It is ok to think of this as a bank. The BANK Serial statement ensures the proper bank is selected for that subroutine section.) If that is how you have those variables defined, then I count 11 other general-purpose bytes being used by the MyBot.sxb program. It does not appear to me that you should be experiencing a variable space problem yet.
Perhaps I do not understand what you are trying to accomplish.
- Sparks
You changed nothing but the device line and now it seems the program is not working? Bummer.
It looks like I will not be of much help. All I can offer is generic advice to check and test all of your connections and to make sure you are using SX/B version 1.51.03 and not another version.
Sorry.
- Sparks
I do not think the UART_SIRCS.SXB program is running out of variable space. I count three general-purpose byte variables and two word variables. So seven general-purpose variable locations are being used. You should have several left by any count!
Likewise utilizing only two sixteen-byte arrays should leave plenty of room for more on any SX version.
I regret that I can not tell you what is wrong... but I do not think it is a lack of variable space.
- Sparks
I have been trying to understand how to best utilize memory and variable space myself. So here is what I have concluded based upon what others are saying.
That is this. The key to this problem will likely be found in the understanding of where your variables reside in relation to the SX memory and how to access them properly when using assembly language subroutines. All of the mental gymnastics involving in tracking memory locations and banks is conveniently handled when using pure SX/B code. Jumping to assembly sometimes requires this to be known and sometimes not.
Here is what I did to try to coax the program you supplied into working properly.
1.) I made the changes I recommended previously creating independent variables for each UART and placed them together into a 16 byte array, a.k.a. a bank. This bank is selected by the UART code with "BANK Serial" commands that were already in place.
2.) I added a "BANK tix" command at the start of your SIRCS subroutine to select the memory bank holding the tix variable (and hopefully all of the other SIRCS variables as well) and a "BANK 0" at the end to place the bank selection back to 0. My hope was that all of the SIRCS variables would conveniently happen to reside within the same bank. Unfortunately, they did not as evidenced by "File register not in current bank" compiler errors.
This is where the whole trick to getting everything to work together comes into play. You need to understand where your variables are when you access then in assembly. (I am so glad SX/B takes care of this automatically!)
If you want to see what I am talking about, download the attached program but move the variable assignments for tmpB1 and tmpW1 back to their previous location, which was right after the SIRCS variable definitions and just before the interrupt statement. Then examine the compiler listing (CTRL-L) of the modified program. You should see the following: (NOTE: Any other program will likely produce a different output.)
You can see that when arranged as I just described tix begins at address $0F, the last address of Bank 0. (The Most Significant Byte (MSB) of tix actually resides one address higher at the start of the next bank!) The rest of the SIRCS variables also reside in the next bank, which is not quite so convenient for quick and easy access.
3.) What I did to provide a "quick fix" for this ("fixing" was not really required as there are ways to deal with variables in different banks) was to move the variable assignments for tmpB1 and tmpW1 so that they occurred earlier in the program listing. That way when variable space is being assigned, all the SIRCS variables happen to fall into the same memory bank! That makes things more convenient, a key element to keeping things simple when using assembly subroutines.
4.) I moved the bit flags for the UARTS to a byte within the same array as Step 1.
5.) Since there are now two UARTS I created duplicated subroutines to access them. This is probably not the most compact way to access them but it was a "quick fix."
I do not know if the modified program I have supplied actually works. I hope you will let us know.
- Sparks
Thanks again
I discovered that you altered the SIRCS interrupt routine from the original posting when you included it in your MyBot.bas program. I was not previously aware of that. It may make a difference. Are you sure your version of it is working fine? It can be very difficult to fix something that has been subject to multiple changes.
At any rate, I am posting an altered version of your program using the original SIRCS subroutine and a slight modification to how you examine the key code. If this should happen to work in some way, so much the better. Otherwise further clarification may be needed if you desire additional help.
- Sparks
I started from scratch, putting together two UARTS, and I have a program that runs DUAL UARTS. I just got through testing it to make sure it works in real time, and not·just in theory. What I wanted to do is make sure I got some code that works, now I will play around with the SIRCS to see if I can get that code inserted, and working. I am happy that I got the DUAL UART to work, at least if the SIRCS does not pan out, I can still use the board in some different manner. Your examples helped me alot. More to come ...
Ray
It was mentioned that there might be some problem with the sircs asm code, so the code listing below reflects the use of non asm sircs code. I just wanted to see if it really was the sircs asm code that was the problem. This code does not work either. So, the conclusion is, on an SX52 chip, if you mix uart with some sircs code neither one works. I do not have enough variable space to try a non serial 'bank' situation.
I am also looking for a UART asm program thats works on an SX52 chip. I tried the example in Gunther's book, but could not get that to work. The example in the download area does not work either. I have not tried the Al Williams example just yet, but I think that will not work either. I have run his UART example on an SX28, and it worked.
Thanks Sparks and Jon for the help.
Ray
Have you considered the run rate differences between the UART and SIRCS ISRs? The UART code specifies an interrupt run rate of 4.34 uS. The SIRCS ISR code from Jon Williams specifies a run rate of 26 uS.
If you have not already considered this you may want to adjust the run rate of the SIRCS code. (26 uS) / (4.34 uS) = 5.99. So you should call the SIRCS code once for every six times the ISR is processed.
Maybe this will help.
- Sparks
There is delay in the interrupt to slow it down to the proper speed.
Ray