Weird code in terminal

TimDonoghue

New Member
Hello, I've been trying to test my board but have been getting some weird string of text instead of what I expect to be char 1/2/3, I'm using a pic 18 high powered board and a pic 08 proto board with the pic18-m2 and 08-m2 chips, the code can be seen here. I've tested just the 08 board and am getting the correct corresponding numbers but when I connect it to the 18-M2 board I'm getting the strange code. Any help would be greatly appreciated.
This is what I ]get on the 08 board = https://gyazo.com/70db87b3c435c6cb0ed4afe5bd335596
This is the strange code/when connected to 18 board= https://gyazo.com/b07495d1906ff45fd1e2f7705562198d
 

AllyCat

Senior Member
Hi Tim,

Welcome to the forum. The two (Hex) characters between each pair of square braces represent a "Non-Printable" ASCII character. Nearly all of yours are either 00 or FF which correspond to a "long" period of either 1 or 0 (i.e. low or high voltage). That might be caused by a baud rate much lower than intended, or just an arbitrary square wave on the TXD pin.

You haven't indicated how the boards are connected, but I'd be looking for a hardware issue, perhaps a spurious PWM output from a pin, or the second PICaxe behaving in an "unexpected" manner such as resetting due to a floating serial input or a missing supply decoupling capacitor.

Cheers, Alan.
 

MPep

Senior Member
Hi Tim,

Welcome to the forum.

Just checked your code in the photos/screengrabs.
In the 18M terminal you are using ASCII (at bottom of the display), but in the 08M2 you have RAW.

The way I see it is that the terminal for the 18M case is correct but you are sending out the incorrect data.
You are seeing the correct data but in the incorrect format is used for sending from the 08M2.

In the 18M getChar subroutine, in sertxd you do not have quotation marks (necessary for ASCII)!

Hope this helps
 

TimDonoghue

New Member
Hi Tim,

Welcome to the forum. The two (Hex) characters between each pair of square braces represent a "Non-Printable" ASCII character. Nearly all of yours are either 00 or FF which correspond to a "long" period of either 1 or 0 (i.e. low or high voltage). That might be caused by a baud rate much lower than intended, or just an arbitrary square wave on the TXD pin.

You haven't indicated how the boards are connected, but I'd be looking for a hardware issue, perhaps a spurious from a pin, or the second PICaxe behaving in an "unexpected" manner such as resetting due to a floating serial input or a missing supply decoupling capacitor.

Cheers, Alan.
I really wish I had a semi decent camera unfortunately I only have a garbage webcam, I've connected the DTR cable to C.4 and TxD to C.3 using bellwire connected to a two pin screw terminal, a crappy pictures here - https://gyazo.com/81e731b69e255cda088ca9976009e03a

I've changed the baud rate on the terminal in editor, I got slightly differing results but nothing that made any sense to me, this is the pic 08 board https://gyazo.com/d7fe7d65b25876316792b1c74b5ee094 and this crappy picture is my pic 18 board https://gyazo.com/6f00e536444d005c38ce311322b11268
Do you have any advice for how to check for a "floating serial input" or the missing supply capacitor, thanks alot for your help, Tim.
 

MPep

Senior Member
Do you have any advice for how to check for a "floating serial input" or the missing supply capacitor, thanks alot for your help, Tim.
Easy. If there is indeed a 10k (or preferably both programming resistors) in place, then all is well.

It looks like both boards are prefab units, probably ok.

Your problem is in the code itself as stated.
 

TimDonoghue

New Member
Hi, thanks for the response, I added the quotation marks and checked both on raw and ascii, but am still getting something resembling this https://gyazo.com/17f0a1db2432a2fa6e24637abaea5032 on each keypress. This is my first project type thing and I'm still completely new to the code, was wondering if you had any clue where the fault might lie, on the pic 08 board I'm getting the correct responses so I think it's just the receiving end for the 18-M2, thanks a bunch! Tim.
 

AllyCat

Senior Member
Hi Tim,

Generally, it's better to post the actual code into the thread, using [ code ] [ /code ] tags, so that we can easily test the code ourselves in the simulator. Also, attaching photos on the forum is preferred because some members refuse, or are unable, to visit external websites (and the photos are more likely to still be available if somebody is "researching" a similar problem in future years).

The almost total preponderance of 00 and FF bytes suggests to me either a very low baud rate, or more likely an "arbitrary" switching signal. If issues are encountered with any "power" project, the first thing to try is to disconnect all the power (i.e. high current or voltage) connections to see if the program then behaves more correctly.

The speed at which the characters are sent to the terminal may give a clue: 9600 baud is almost 1,000 characters per second, so the screen could fill very quickly. 50 Hz "mains hum" (pickup) should be noticeably slower, and if they are even slower, would suggest an intermittent (hardware) "bad connection".

Cheers, Alan.
 

AlbertZ

Senior Member
Hello All,

I have been working with Tim to develop this project for a course he is taking at college. His goal was to simulate a vending machine using a keypad, microprocessor and some motors. We started with a standard matrix keypad and an 08M2 processor. We chose to use a resistor matrix to produce an analog voltage level that differs for each key press. We would then decode the key press and send the output to a master processor that would drive the motors. The thought was to have three inexpensive motors connected to CH1030A project board. Part 1 of the project seems to be working correctly. He is decoding the keypress and sending the correct ASCII character to the serial terminal.

The problem it would seem is the communication between the 08M2 and the 18M2 on the project board.

Here is the code for the 08M2:
Code:
' ============== KeypadDriver.bas ===============

' This program uses an ADC approach to decoding
' a 4X3 matrix keypad. It notifies MP that a new
' character is available, then sends it serially.

' === Constants ===
	symbol fromKP = C.2		' Keypad ADC input
	symbol fromMP = C.3		' input (DTR) from MP
	symbol   toMP = C.4		' serout (TxD) to MP
	
' === Variables ===
	symbol  key = w0			' ADC key value
	symbol char = b2			' corresponding char
	symbol junk = b3			' throwaway char	
	
' === Directives ===
	#com 3				' specify serial port
	#picaxe 08M2			' specify processor
	#terminal off			' disable terminal window
	
' ============= Begin Main Program ==============
setfreq m8
dirsC = %00010011				' C.2 & C.3 = inputs

do 	
wait_for_keypress:
  readadc fromKP, junk
	if junk < 5 then wait_for_keypress

	pause 60				' debounce keypress	
	readadc10 fromKP, key		        ' get ADC value
		
wait_for_release:	
	readadc fromKP, junk
	if junk > 5 then wait_for_release
	
	select case key			' decode keypress
		case < 384 : char = 49		' 1
		case < 401 : char = 50		' 2
		case < 435 : char = 51		' 3
		case < 474 : char = 52		' 4
		case < 499 : char = 53		' 5
		case < 558 : char = 54		' 6
		case < 628 : char = 55		' 7
		case < 696 : char = 56		' 8
		case < 767 : char = 57		' 9
		case < 884 : char = 42		' *
		case < 976 : char = 48		' 0
		else	    : char = 35	' #
	end select
	
	high toMP					' data available
	pulsin fromMP,1, junk			' junk is junk,
	low toMP					' we're just waiting
	pause 2					' allow time for MP
							' to set up serin
	serout toMP,N2400_8,(char)		' send char to MP	
loop
Here is the code for the 18M2:
Code:
' =========================== KeypadTest.bas ===========================

' This program runs on an 18M2.  It receives data from the keypad (KP)
' and sends it to the terminal window for display

' === Constants ===
	symbol fromKP = C.4			
	symbol toKP  = C.3

' === Variables ===
	symbol char   = b0		' character to be sent to terminal
	symbol KPflag = pinC.3		
' Note: KPflag is a variable because its value can change
	
' === Directives ===
	#com 3				' specify COM port
	#picaxe 18M2			' specify processor
	#no_data			' save time downloading
	#terminal 9600			' open terminal window	

' ======================= Begin Main Program ========================
setfreq m8
dirsC = %10110111				' configure pinC.3 as input	
low toKP					' initialize to low

' === Main Program Loop ===	
wait_for_keypress:
do
  	pause 100				' pretend to be busy
	if KPflag = 1 then gosub getChar	' go get new char
loop

' ============== End Main Program - Subroutines Follow ==============
getChar:
	pulsout toKP, 2		'10uS "send it" pulse					
	pause 1				' allow time for keypad to 
					' lower its output
	serin fromKP, N2400_8, char	' get char
	sertxd (char, cr, lf)		' send it to terminal
	return
 

hippy

Technical Support
Staff member
Code:
	high toMP					' data available
	pulsin fromMP,1, junk			' junk is junk,
	low toMP					' we're just waiting
	pause 2					' allow time for MP
							' to set up serin
	serout toMP,N2400_8,(char)
Setting the 'toMP' line high then low before sending the 'char' on the same line is probably causing the $00 and $FF characters to be seen, that's the spurious output AlleyCat suggested in post #2.
 

hippy

Technical Support
Staff member
There seems to be some mismatch within the 18M2 code and with the circuit diagram.

In the 18M2 code 'toKP' (C.3) seems to be the output from the 18M2 to the keypad 08M2 and used as such, but C.3 is set as an input by the "dirsC=" and 'KPflag' (pinC.3) is used as an input.

In the circuit diagram the interconnect appears to be using 18M2 pins C.6 and C.7.

With those issues it is not easy to tell if the algorithm and handshaking is sound or not.
 

TimDonoghue

New Member
Thanks for everyones help, apparently Hippy got it spot on and everything works smoothly. It's amazing to see so many people willing to help out on these forums! Thanks a bunch, Tim.
 
Top