Shop OBEX P1 Docs P2 Docs Learn Events
Detecting VGA monitor connection — Parallax Forums

Detecting VGA monitor connection

ozpropdevozpropdev Posts: 2,792
edited 2019-10-10 23:27 in Propeller 2
Here's a idea (shamelessly stolen from Tubular! :) ) to detect if a VGA monitor is connected to the P2 and where its located.
It simply enables pins with a 1k5 pullup and starts the ADC bitstream as well as a smart pin counter mode.
If a monitor is connected a voltage divider scenario is present and the pin reads lower.
The code returns the VGA base pin or the value 99 if no monitor detected.
con

	_1k5_pu = %001 << 11
	_adc_pinA_1x = %100011 << 15
	_inc_ahigh = %01111 << 1

	_mode = _adc_pinA_1x | _1k5_pu | _inc_ahigh

dat

'Returns vga  monitor basepin in pb
'pb = 99 ,no monitor detected.

detect		mov	pb,#%001_000000

loop		wrpin	##_mode,pb	'1k5 pullup + adc + inc on A high
		wxpin	##$FFFF,pb	'64k samples
		wypin	#0,pb
		drvh	pb		'enable smartpin and drive pin high
		setse1	pb		'rising edge event 

		rep	#2,#2		'do twice
		 waitse1		'wait for smart pin result	
		 rdpin	val,pb		'get result from smartpin

		cmp	val,##$3500 wcz
	if_a	wrpin	#0,pb		'reset pin drive and adc
	if_a	fltl	pb		'reset smart pin
	if_b	and	pb,#$3f		'adjust result
	if_b	ret

		add	pb,#8		'next pin base
		cmp	pb,#%001_000000 + 56 wz
	if_ne	jmp	#loop
	_ret_	mov	pb,#99		'no monitor detected
		

Comments

  • evanhevanh Posts: 15,916
    I love the way conditional execution absorbs simple logic without branching. Just a pity it costs extra instruction bits all the time.
  • Wow nice code there Oz. And quick work too

  • RaymanRayman Posts: 14,646
    edited 2019-10-11 13:08
    Looks like a pull down on pin #4 of VGA connector could be used also...
    https://en.wikipedia.org/wiki/Display_Data_Channel

    Actually, with so many P2 I/O pins, wonder if it makes any sense to use the I2C connection on the VGA monitor...
    I thought about this for a second and then decided that almost all monitors take 1080p@60Hz these days, so there's not much to be gained...
Sign In or Register to comment.