PDA

View Full Version : Serial Output - Help



Tom P
01-07-2009, 09:42 PM
********NEED SOME HELP PLEASE *****

The program below displays two ADC channels on a TV screen,but I·want to·send the two readings out P3 on Propeller demo board via serial communication for remote display. I added the lines in red below but I do not get intelligible data out the serial port to an LCD display. I can read gibberish but cannot even read string text?·Where did I go wrong?·· HELP

{
********************************************
··· Test LTC1298 Demo
********************************************
··· Charlie Dixon (CDSystems) 2007
********************************************
}
CON
· _CLKMODE = XTAL1 + PLL16X
· _XINFREQ = 5_000_000
· _stack = ($3000 + $3000 + 100) >> 2·················· 'accommodate display memory and stack
· x_tiles = 16
· y_tiles = 12
· x_screen = x_tiles << 4
· y_screen = y_tiles << 4
· width = 0············ '0 = minimum
· x_scale = 1·········· '1 = minimum
· y_scale = 1·········· '1 = minimum
· x_spacing = 6········ '6 = normal
· y_spacing = 13······· '13 = normal
· x_chr = x_scale * x_spacing
· y_chr = y_scale * y_spacing
· y_offset = y_spacing / 6 + y_chr - 1
· x_limit = x_screen / (x_scale * x_spacing)
· y_limit = y_screen / (y_scale * y_spacing)
· y_max = y_limit - 1
· y_screen_bytes = y_screen << 2
· y_scroll = y_chr << 2
· y_scroll_longs = y_chr * y_max
· y_clear = y_scroll_longs << 2
· y_clear_longs = y_screen - y_scroll_longs
· paramcount = 14
· display_base = $5000
· bitmap_base = $2000
VAR
··· long· tv_status···· '0/1/2 = off/visible/invisible·········· read-only
··· long· tv_enable···· '0/? = off/on··························· write-only
··· long· tv_pins······ '%ppmmm = pins·························· write-only
··· long· tv_mode······ '%ccinp = chroma,interlace,ntsc/pal,swap write-only
··· long· tv_screen···· 'pointer to screen (words)·············· write-only
··· long· tv_colors···· 'pointer to colors (longs)·············· write-only··············
··· long· tv_hc········ 'horizontal cells······················· write-only
··· long· tv_vc········ 'vertical cells························· write-only
··· long· tv_hx········ 'horizontal cell expansion·············· write-only
··· long· tv_vx········ 'vertical cell expansion················ write-only
··· long· tv_ho········ 'horizontal offset······················ write-only
··· long· tv_vo········ 'vertical offset························ write-only
··· long· tv_broadcast· 'broadcast frequency (Hz)··············· write-only
··· long· tv_auralcog·· 'aural fm cog··························· write-only
··· word· screen[x_tiles * y_tiles]
··· long· colors[64]
··· long· x, y, cel, far····
OBJ
··· tv··· :···· "TV"
··· gr··· :···· "CD_Graphics"
··· Num·· :···· "CD_Numbers"
··· adc·· :···· "CD_LTC1298"
··· SER·· :···· "FullDuplexSerial"···
PUB MAIN | i,dx,dy,Temp
ser start(4,3,0,2400)

··· 'start tv
··· longmove(@tv_status, @tvparams, paramcount)
··· tv_screen := @screen
··· tv_colors := @colors
··· tv.start(@tv_status)
··· 'init colors
··· repeat i from 0 to 63
····· colors[i] := $00001010 * (9) & $F + $2B060C02·· '$00001010 * (5+4) & $F + $2B060C02
··· 'init tile screen
··· repeat dx from 0 to tv_hc - 1
····· repeat dy from 0 to tv_vc - 1
······· screen[dy * tv_hc + dx] := display_base >> 6 + dy + dx * tv_vc + ((dy & $3F) << 10)
·· 'start and setup graphics, LTC1298 ADC chip
··· gr.start·········································· · 'Start Graphics Driver
··· gr.setup(16, 12, 128, 96, bitmap_base)
··· adc.start(0)······································ · 'Initialize ADC chip
'************************************************* *************************************************
' Main Program Loop to get and display ADC data to TV Screen
'************************************************* *************************************************
··· repeat
····· dira[3] ~~
····· gr.clear······································· 'Num.ToStr(Temp, Num#DEC)
····· gr.colorwidth(1, 2)···························· 'Resolution = 5.00V / 4096 = 0.00122
····· gr.textmode(1,1,7,%0000)························
····· Temp := adc.GetADC(0) * 5000/4096·························
····· gr.text(-128,65,string("ADC Channel 0: ","··· mV"))
····· gr.text(-25,65,Num.ToStr(Temp, Num#DEC))
····· Temp := adc.GetADC(1)· * 5000/4096
····· gr.text(-128,35,string("ADC Channel 1: ","··· mV"))
····· gr.text(-25,35,Num.ToStr(Temp, Num#DEC))
····· gr.copy(display_base)
····· ser.tx(10)
····· ser.tx(13)
····· waitcnt (500_000 * 50 + cnt)
····· ser.str (string ("ADC Channel 0: ","··· mV"))
····· ser.dec·(Temp)
····· ser.tx (10)
····· ser.tx (13)
····· waitcnt (500_000 * 50 + cnt)
····· ser.str (string ("ADC Channel 1: ","··· mV"))
····· ser.dec (Temp)
····· ser.tx (10)
····· ser.tx(13)
DAT
Zero··················· word··· $30
DP····················· word··· $2E
Hyphen················· word··· $2D
tvparams··············· long··· 0·············· 'status
······················· long··· 1·············· 'enable
······················· long··· %001_0101······ 'pins
······················· long··· %0000·········· 'mode
······················· long··· 0·············· 'screen
······················· long··· 0·············· 'colors
······················· long··· x_tiles········ 'hc
······················· long··· y_tiles········ 'vc
······················· long··· 10············· 'hx
······················· long··· 1·············· 'vx
······················· long··· 0·············· 'ho
······················· long··· 0·············· 'vo
······················· long··· 0·············· 'broadcast
······················· long··· 0·············· 'auralcog
color_schemes·········· long··· $BC_6C_05_02
······················· long··· $0E_0D_0C_0A
······················· long··· $6E_6D_6C_6A
······················· long··· $BE_BD_BC_BA
DAT
···· {<end of object code>}
····
{{

Peter Jakacki
01-07-2009, 10:12 PM
Don't try to make the transmit an output independently ( dira~~ ) as the serial cog already does this and you have two cogs "fighting" over the pin.

*Peter*

StefanL38
01-07-2009, 10:17 PM
Hello Tom,

the commands seem to be OK.

What kind of display is this ?

LCD? PC terminalsoftware ?

the commands
ser.tx (10)
ser.tx(13)

let me guess it is a PC-terminalsoftware
LCDs usually don't react on linefeed carriage return
it even might be that these values are used for other purposes like changing baudrate or whatever

Is it a 5V device ? Then you have to use a 1kOhm resistor between Prop-IO-PIN and the device
does the device have a baudrate of 2400 ?

Not long ago there was a thread for a LCD where some initial commands has to be send to the LCD for proper operation
so the forum needs to know the type of device and a datasheet of this device

Maybe you have to use one of the inverted modes or pull-up-resistors
or a voltage-levelshifter to 5V or true RS232-levels

how should we know that without knowing details about the device ?

best regards

Stefan

Tom P
01-07-2009, 10:42 PM
First -- responding to Peter in the above comment: who says Don't try to make the transmit an output independently ( dira~~ ) as the serial cog already does this and you have two cogs "fighting" over the pin. How do I change this as to not interfere?

Also

For test purposes, I am using an ILM-216 LCD display to display the program data at 2400 baud.
Looking at the --- ser start(4,3,0,2400) command, How do I know if I set the MODE correctly, where can I get more info on mode settings for serial.

thanks for any and all help
Tom

Peter Jakacki
01-07-2009, 11:29 PM
Delete the dira[ 3 ]~~ instruction just after the main repeat.

Your mode should be 0 unless the lcd is expecting RS232 data and you are connecting straight from the Prop's I/O in which you will need to invert the signals by setting mode to 3 which inverts the rx and tx. For more info simply look at the comments that are embedded in the serial object.

*Peter*

Tom P
01-08-2009, 12:20 AM
OK, I removed the dira ~~ instruction and not too much changed until I changed to the MODE to (3) in the serial statement -ser start(4,3,3,2400). At that point I began seeing the serial string statement showing ADC Channel 0 and ADC Channel 1, but the data, that I see doesn't seem to look correct from both ADC channels. Its like the actual data is one channel and not the other. Did I do something wrong in the -- ser.dec (Temp) statement which does reflect both channels separately???

I'am almost there but not quite!!!
thanks
Tom

TJHJ
01-08-2009, 03:03 AM
2 questions,

You say LCD display, is this a two way or 1 way display? You might be doing an overkill using FD serial if it is a one way LCD display.

As for your last post, you read the value into temp, and overwrite it before you print it.





'************************************************* *************************************************
' Main Program Loop to get and display ADC data to TV Screen
'************************************************* *************************************************
repeat
dira ~~
gr.clear 'Num.ToStr(Temp, Num#DEC)
gr.colorwidth(1, 2) 'Resolution = 5.00V / 4096 = 0.00122
gr.textmode(1,1,7,%0000)


'' HERE CH 0 is stored in temp.
Temp := adc.GetADC(0) * 5000/4096

''TV graphics is updated but that does not affect your serial output.
gr.text(-128,65,string("ADC Channel 0: "," mV"))
gr.text(-25,65,Num.ToStr(Temp, Num#DEC))

'' Before you printed CH0 to the LCD display you now have stored CH1 in temp.
Temp := adc.GetADC(1) * 5000/4096
gr.text(-128,35,string("ADC Channel 1: "," mV"))
gr.text(-25,35,Num.ToStr(Temp, Num#DEC))
gr.copy(display_base)
ser.tx(10)
ser.tx(13)
waitcnt (500_000 * 50 + cnt)

' Now here you start sending data out to the LCD screen.
ser.str (string ("ADC Channel 0: "," mV"))

' You want to send CH0 here, but actually are sending CH1 because you overwrote it before you did anything with it.
ser.dec (Temp)
ser.tx (10)
ser.tx (13)
waitcnt (500_000 * 50 + cnt)

' Now you sent CH1 again.
ser.str (string ("ADC Channel 1: "," mV"))
ser.dec (Temp)
ser.tx (10)
ser.tx(13)






A simple fix is to use two different variable names, it will make you life simpler, but if you need to do it this way.






'************************************************* *************************************************
' Main Program Loop to get and display ADC data to TV Screen
'************************************************* *************************************************
repeat
dira ~~
gr.clear 'Num.ToStr(Temp, Num#DEC)
gr.colorwidth(1, 2) 'Resolution = 5.00V / 4096 = 0.00122
gr.textmode(1,1,7,%0000)

' Here is CH0 for the adc.
Temp := adc.GetADC(0) * 5000/4096
gr.text(-128,65,string("ADC Channel 0: "," mV"))
gr.text(-25,65,Num.ToStr(Temp, Num#DEC))

' Now send it to the LCD before you update with channel 1.
ser.tx(10)
ser.tx(13)
waitcnt (500_000 * 50 + cnt) ' Im not sure why you have interspaced waitcnts but I left them.
ser.str (string ("ADC Channel 0: "," mV"))
ser.dec (Temp)
ser.tx (10)
ser.tx (13)


'' Now get CH1 and store in Temp.
Temp := adc.GetADC(1) * 5000/4096
gr.text(-128,35,string("ADC Channel 1: "," mV"))
gr.text(-25,35,Num.ToStr(Temp, Num#DEC))
gr.copy(display_base)


' Now CH1 is in temp send it to the LCD again.
waitcnt (500_000 * 50 + cnt)
ser.str (string ("ADC Channel 1: "," mV"))
ser.dec (Temp)
ser.tx (10)
ser.tx(13)






You see what is going on, you are writing over the value of Temp before you update your LCD screen, the tv one works because it updates the graphics palette, but doesn't update the screen until GR.copy is called.

Hope this helps.

TJ

Tom P
01-08-2009, 08:37 PM
TJ:

I think I see what you are trying to say about overwriting the value of (Temp).
BUT ... I inserted the "simple fix" main program loop section above -- into the program but now NOTHING displays on the TV or LCD?
What are we missing here!
Tom

Tom P
01-08-2009, 09:50 PM
TJ:

Disregard the last post !!!!
I re-entered the code section and it works fine.
thanks so much for your help
Tom