Evan-
Code here:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH ' & 0x0F 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH ' & 0x0F 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
Notice the ' before the & above in the non-masking lines
Copied from the serial console:
Address Units:0
Address Tens:0
Code that works:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH & 0x0F 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH & 0x0F 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
Copied from serial console:
Address Units:5
Address Tens:3
Address:35
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If PORTH is an input port then how would reading the LAT register read the state of the pins?
It would just read the setting of the LAT register, not the PORT pin values.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This did NOT work BTW, gave ZERO:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH '& 0x0F 'Gets the units digit of the Address and strips off high nibble
NOP
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH '& 0x0F 'Gets the tens digit of Address and strips off high nibble
NOP
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This also did NOT work, using LATH:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
' Address1 = PORTH '& 0x0F 'Gets the units digit of the Address and strips off high nibble
Address1 = LATH 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
' Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
Address10 = LATH 'Gets the tens digit of the Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
NOP
Address1 = PORTH 'Gets the units digit of the Address and strips off high nibble
...
...
...
BCD1 = 0 'Resets the units BCD common back to LOW
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
NOP
Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
....
....
....
You are adding the NOP after setting the port.pin high ( as this port.pin is the source of the input for the next read). See about.
See if this works,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 18F67K40 has IO slew rate control for the port pins, and it defaults to slow mode (SLRCONx registers default to 0xFF).
If you have this:
BCD1 = 1 'Sets the units digit of Address HIGH
Address1 = PORTH 'Gets the units digit of the Address
PORTH is read on the next cycle right after setting the pin high, so it may not have time to slew (slow mode).
When you add code to mask the upper unused nibble:
BCD1 = 1 'Sets the units digit of Address HIGH
Address1 = PORTH & 0x0F 'mask upper nibble (adds one cycle)
an additional instruction cycle gets added before PORTH is read, so it has time to settle.
That has the same timing as:
BCD1 = 1 'Sets the units digit of Address HIGH
nop
Address1 = PORTH
You can set the IO slew rate for PORTG to normal using SLRCONG = 0, but it might be a good idea to add a 'nop' after setting PORTG outputs anyway, and mask the unused bits of PORTH.
' wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
NOP 'Wait a cycle
Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
NOP 'Wait a cycle
Address = (Address10 * 10) + Address1 'Creates the board address
What I have learned - go back and re-read ALL about ALL port registers <grin>.
It has been an illuminating journey, Thanks to All who helped in this.
Regards, and a hoist of an Adult Beverage in your honor later this evening!
-Steve</grin>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Would you add some debug to the program.
After each read show the assigned value to the serial terminal. What are those values?
Please try with the mask and without the mask.
Thanks
Evan-
Code here:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH ' & 0x0F 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH ' & 0x0F 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
Copied from the serial console:
Address Units:0
Address Tens:0
Code that works:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH & 0x0F 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH & 0x0F 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
Address Units:5
Address Tens:3
Address:35
Ok. That ain't right... should be the same.
Can you send me the source and ASM for both tests. Thank you
I should have spotted this one days ago. Sorry.
Address1 = PORTH
should beAddress1 = LATTH
andAddress10 = PORTH
should beAddress10 = LATTH
The debugger shows the operation as correct,
The reason for the mask working is the extra cycles to complete the mask meant PORTH was settled.
I would recommend use of LATH and I am happy. :-)
Last edit: Anobium 2023-09-11
If PORTH is an input port then how would reading the LAT register read the state of the pins?
It would just read the setting of the LAT register, not the PORT pin values.
I am sharing what I see in the simulator. Steve can try on real silicon.
This is a read-modity issue on BCD1 not PORTH
I have tested on silicon.
Test code.
Test code with a NOP added. just like the masking operation with 0X0F.
This did NOT work BTW, gave ZERO:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
Address1 = PORTH '& 0x0F 'Gets the units digit of the Address and strips off high nibble
NOP
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
Address10 = PORTH '& 0x0F 'Gets the tens digit of Address and strips off high nibble
NOP
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
The NOP would be after setting the BCD line to 1.
This also did NOT work, using LATH:
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
' Address1 = PORTH '& 0x0F 'Gets the units digit of the Address and strips off high nibble
Address1 = LATH 'Gets the units digit of the Address and strips off high nibble
HSerPrint "Address Units:"
HSerPrint Address1
HSerSend 13
HSerSend 10
BCD1 = 0 'Resets the units BCD common back to LOW
wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
' Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
Address10 = LATH 'Gets the tens digit of the Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
Address = (Address10 * 10) + Address1 'Creates the board address
Agree. the LAT will not resolve. The NOP may.
Evan-
see post before my last, NOPdid not work.
At least one NOP did not.
That NOP was in the wrong place.
'Gets address
BCD1 = 1 'Sets the units digit of BCD switch common Address HIGH
NOP
Address1 = PORTH 'Gets the units digit of the Address and strips off high nibble
...
...
...
BCD1 = 0 'Resets the units BCD common back to LOW
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
NOP
Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
....
....
....
You are adding the NOP after setting the port.pin high ( as this port.pin is the source of the input for the next read). See about.
See if this works,
I think I see what's likely going on here...
The 18F67K40 has IO slew rate control for the port pins, and it defaults to slow mode (SLRCONx registers default to 0xFF).
If you have this:
PORTH is read on the next cycle right after setting the pin high, so it may not have time to slew (slow mode).
When you add code to mask the upper unused nibble:
an additional instruction cycle gets added before PORTH is read, so it has time to settle.
That has the same timing as:
You can set the IO slew rate for PORTG to normal using SLRCONG = 0, but it might be a good idea to add a 'nop' after setting PORTG outputs anyway, and mask the unused bits of PORTH.
Last edit: Jerry Messina 2023-09-12
Jerry, yep. That was my working theory. A great explanation.
Thanks Jerry - I overlooked that register.
Will also add the NOP just to try everything.
This did NOT work:
config SLRCONH = 0 'Sets SLEW to max rate
config SLRCONG = 0 'Sets SLEW to max rate
Gentlemen-
The code now works WITHOUT using the masking line.
Code for address here:
config SLRCONH = 0 'Sets SLEW to max rate
config SLRCONG = 0 'Sets SLEW to max rate
' wait 100 us 'Wait just a bit
BCD10 = 1 'Sets the tens digit of BCD switch common Address HIGH
NOP 'Wait a cycle
Address10 = PORTH 'Gets the tens digit of Address and strips off high nibble
HSerPrint "Address Tens:"
HSerPrint Address10
HSerSend 13
HSerSend 10
BCD10 = 0 'Resets the tens BCD common back to LOW
NOP 'Wait a cycle
Address = (Address10 * 10) + Address1 'Creates the board address
What I have learned - go back and re-read ALL about ALL port registers <grin>.
It has been an illuminating journey, Thanks to All who helped in this.
Regards, and a hoist of an Adult Beverage in your honor later this evening!
-Steve</grin>
Good to hear!
Learning all time here!