communication between main program and cog help needed
plinius10
Posts: 1
Hello Propellerheads:)
I've started working with the propeller a view days back and am comming along quite nice.
I'm coding an video overlay together based on the HITT video overlay. I'm displaying video on my pal display when there is a video scoure present and when there is not, the propeller generates the signal this all works very good.
My problem is I can't seem to understand how i can feed information from the video overlay object back to my main program. I have tried several options but none of them seem to work.
I hope one of you sees what I'm doing wrong.
Here are the two important objects that I use:
The Main program:
And the Overlay code:
So what i do is add the two lines
to the main routine and than in the main loop i write the variable to the main ram with this line
Am i right to believe that that should be enough to read the _overlayMode value stored in cargo in the main program?
The mainprogram als should convert the _overlayMode value (which is a long right?) to a string value so i can display it on screen with the graphics method "text"
i hope i made myself clear so you understand:) and that someone has the time to take a look at the giant wall of code:P
Thanks in advance!
I've started working with the propeller a view days back and am comming along quite nice.
I'm coding an video overlay together based on the HITT video overlay. I'm displaying video on my pal display when there is a video scoure present and when there is not, the propeller generates the signal this all works very good.
My problem is I can't seem to understand how i can feed information from the video overlay object back to my main program. I have tried several options but none of them seem to work.
I hope one of you sees what I'm doing wrong.
Here are the two important objects that I use:
The Main program:
CON _CLKMODE = XTAL1 + PLL8X _XINFREQ = 10_000_000 x_tiles = 16 y_tiles = 12 VAR long PAL_Mode long bitmap[3072] long display[3072] long cargo long strCargo OBJ overlay : "HITT_Video_Overlay_018" gr : "Graphics" Clock : "Clock_mini" num : "Simple_Numbers" PUB HhDd overlay.start(@PAL_mode) gr.start gr.setup(x_tiles, y_tiles, 0, 0, @display) gr.textmode(1,1,6,0) Clock.Init(_XINFREQ) ' set up clock for accuate 10/second Clock.SetClock(_CLKMODE) ' video update rate Clock.MarkSync repeat ' loop until death gr.colorwidth(1, 0) ' Set Color and Width gr.clear gr.text(50,50,conf) 'This should put the value of the overlaymode on the screen gr.finish gr.copy(@bitmap) Clock.WaitSyncMSec(100) PUB conf strCargo := num.dec(cargo) return strCargo
And the Overlay code:
VAR LONG cog ' Video cog number (used to stop cog) PUB Start(VideoActive_PalMode_Screen) ' Start overlay COG cog:=CogNew(@OverlayAsm, VideoActive_PalMode_Screen) PUB Stop if cog cogstop(cog~ - 1) DAT ORG OverlayAsm MOV _videoActiveAddr, par MOV _videoActiveValue,#0 WRLONG _palModeValue, _palModeAddr MOV _palModeAddr,par ADD _palModeAddr,#4 RDLONG _palModeValue,_palModeAddr MOV _screenAddr,par ' Get address of screen memory ADD _screenAddr,#8 'This is my custom line of assembler<<<<------------------ MOV _cargoAddr,par ' Get address of cargo ADD _cargoAddr,#12 ' Setup cnta to use video hardware MOVI ctra,#%000001_111 ' Video PLL x16 MOV frqa,VideoFreq ' Set video freq to 128MHz (80MHz / 10) = 8MHz * 16 = 128MHz ' Setup VSU (initially off) MOVI vcfg,#%0_00_0_0_0_000 ' Generation off MOVS vcfg,#%0000_1100 ' Use pin P18,P19 (2&3 of group 2) for output MOVD vcfg,#2 ' Use pin group 2 (P16-P23) MOV vscl,VideoScale ' Setup dot clock to 5.818182 MHz ' Setup I/O pins ANDN dira,_syncPinMask ' Make Sync Pin an Input OR dira,_videoPinMask ' Make video Pin an Output ANDN dira,_genPinsMask ' Make gen Pins an Inputs MOV _overlayMode,#1 ' 1 = Gen Mode JMP #GenMode OvrMain ' Main overlay generation loop 'This is my custom line of assembler<<<<------------------ WRLONG _overlayMode, _cargoAddr ' Set video active value WRLONG _videoActiveValue,_videoActiveAddr ' Wait for sync pin to go high, or timeout waiting MOV _timeCnt,SyncTimeoutValue WaitSyncHigh AND _syncPinMask,ina WZ, NR IF_Z DJNZ _timeCnt,#WaitSyncHigh IF_Z MOV _overlayMode,#1 ' Timed-out, switch to generate mode IF_Z JMP #GenMode WAITPNE _syncPinMask,_syncPinMask ' Wait for Sync pin to go low MOV _timeCnt,#480 ' Wait 6uSec @ 80MHz ADD _timeCnt,cnt WAITCNT _timeCnt,#0 ' If sync is STILL low then we are in VSYNC AND _syncPinMask,ina WZ, NR ' Is Sync Pin still low ? IF_Z RDLONG _palModeValue,_palModeAddr IF_Z CMP _lineCnt,#200 WC IF_Z_AND_C JMP #DontCheckPal IF_Z CMP _lineCnt,#287 WC IF_Z_AND_NC MOV _palModeValue,#1 IF_Z_AND_C MOV _palModeValue,#0 IF_Z WRLONG _palModeValue,_palModeAddr DontCheckPal IF_Z MOV _lineCnt,#0 ' Yes, reset line counter IF_Z MOV _currentAddr,_screenAddr ' Yes, reset current address IF_Z JMP #OvrMain ' Yes, go back to main loop ADD _lineCnt,#1 ' Adjust line counter ' If we are not on a visable part of the screen, just go back and wait CMP _palModeValue,#0 WZ IF_Z CMP _lineCnt,#40 WC ' Don't draw until line 40 NTSC IF_NZ CMP _lineCnt,#65 WC IF_C MOV _videoActiveValue,#0 IF_C JMP #OvrMain IF_Z CMP _lineCnt,#232 WC ' Don't draw after line 232 NTSC IF_NZ CMP _lineCnt,#257 WC IF_NC MOV _videoActiveValue,#0 IF_NC JMP #OvrMain MOV _timeCnt,#230 ' Wait for left margin ADD _timeCnt,cnt WAITCNT _timeCnt,#0 ' Set video active to 1 MOV _videoActiveValue,#1 MOVI vcfg,#%0_01_1_0_0_000 ' Enable video hardware for VGA generation ANDN outa,_videoSinkPin ' Allow Sink pin to darken image MOV _horzCnt,#16 ' Draw 16 longs per line (16*16 = 256 pixels per line) :NextPattern RDLONG _dotPattern, _currentAddr ' Get dot pattern from global RAM XOR _dotPattern,FlipBlackBit ' Flip black bit so that 0=Transparent ADD _currentAddr,Next_Col ' Adjust current address to next LONG WAITVID VideoColorsOverlay,_dotPattern ' Send dot pattern to video hardware DJNZ _horzCnt,#:NextPattern ' Do next dot pattern SUB _currentAddr,Next_Line WAITVID videoColorsOvrBlank,#0 ' Clear video hardware OR outa,_videoSinkPin ' Don't allow Sink pin to darken image MOVI vcfg,#%0_00_0_0_0_000 ' Disable video hardware JMP #OvrMain ' Go back to main loop '-------------------------------------- GenMode MOVS vcfg,#%0000_0001 ' Use only pin P16 (pin 0 of group 2) for video output ANDN dira,_syncPinMask ' Make Sync Pin an Input ANDN dira,_videoPinMask ' Make video Pin an Input OR dira,_genPinsMask ' Make gen sync Pins Outputs ANDN outa,_genPinsMask ' Make both pins low MOV _lineCnt,#0 ' 0-2 = VSync; 3-41=TopBlank; 42-233=Image, 234-261=BottomBlank MOV _overlayMode,#1 ' If bit1 = 1, then first time through ' Purge video hardware MOVI vcfg,#%0_01_1_0_0_000 ' Enable video hardware for VGA generation WAITVID videoColorsGen,#0 ' Clear video hardware MOVI vcfg,#%0_00_0_0_0_000 ' Disable video hardware MOV _lineTimerCnt,cnt ' Get initial cnt value GenMain MOV _videoActiveValue,#0 ' Assume not generating video CMP _lineCnt,#3 WC ' Are we in VSync ? IF_C JMP #GenVSync ' Yes, jump CMP _palModeValue,#0 WZ IF_Z CMP _lineCnt,#42 WC ' Are we in TopBlank ? NTSC IF_NZ CMP _lineCnt,#67 WC IF_C JMP #GenBlankLine ' Yes, jump IF_Z CMP _lineCnt,#234 WC ' Are we in Image ? NTSC IF_NZ CMP _lineCnt,#259 WC IF_C JMP #GenActiveLine ' Yes, jump JMP #GenBlankLine ' We must be in BottomBlank GenVSync ANDN outa,_genPinSyncMask ' Make gen sync pin low (sync level output) JMP #GenDone ' Done for this line GenBlankLine ANDN outa,_genPinSyncMask ' Make gen pin low (sync level output) MOV _timeCnt,#376 ' Delay 4.7uSec @ 80MHz ADD _timeCnt,cnt WAITCNT _timeCnt, #0 OR outa,_genPinSyncMask ' Make gen pin high (black level output) MOV _currentAddr,_screenAddr ' Reset current screen address JMP #GenDone ' Done for this line GenActiveLine MOV _videoActiveValue,#1 ANDN outa,_genPinSyncMask ' Make gen pin low (sync level output) MOV _timeCnt,#376 ' Delay 4.7uSec @ 80MHz ADD _timeCnt,cnt WAITCNT _timeCnt,#0 OR outa,_genPinSyncMask ' Make gen pin high (black level output) MOV _timeCnt,#430 ' Wait 3uSec @ 80MHz (Left margin) ADD _timeCnt,cnt WAITCNT _timeCnt,#0 MOVI vcfg,#%0_01_1_0_0_000 ' Enable video hardware for VGA generation MOV _horzCnt,#16 ' Draw 16 longs per line (16*16 = 256 pixels per line) :NextPattern RDLONG _dotPattern, _currentAddr ' Get dot pattern from global RAM ADD _currentAddr,Next_Col ' Adjust current address to next LONG WAITVID VideoColorsGen,_dotPattern ' Send dot pattern to video hardware AND _syncPinMask,ina WZ, NR ' Is Sync input low ? IF_Z MOV _overlayMode,#0 ' If Sync input is low video input detected, switch to overlay mode DJNZ _horzCnt,#:NextPattern ' Do next dot pattern SUB _currentAddr,Next_Line WAITVID videoColorsGen,#0 ' Clear video hardware MOVI vcfg,#%0_00_0_0_0_000 ' Disable video hardware GenDone ADD _lineCnt,#1 ' Advance line count RDLONG _palModeValue,_palModeAddr CMP _palModeValue,#0 WZ IF_Z CMP _lineCnt,#262 WZ ' If _lineCnt reaches 262, then reset it to zero NTSC IF_NZ CMP _lineCnt,#312 WZ IF_Z MOV _lineCnt,#0 ADD _lineTimerCnt,LineTimerValue ' Wait for next video line ' Set video active variable WRLONG _videoActiveValue,_videoActiveAddr WAITCNT _lineTimerCnt, #0 TJNZ _overlayMode,#GenMain MOVS vcfg,#%0000_1100 ' Use pin P18,P19 (2&3 of group 2) for output ANDN dira,_genPinsMask ' Otherwise switch to overlay mode, make gen sync Pin an Input OR dira,_videoPinMask ' Make video Pin an Output JMP #OvrMain ' Jump to overlay code ' Constants for OverlayAsm VideoFreq LONG $1999_9999 ' = 8 Mhz FROM 80Mhz clock x 16PLL = 128MHz VideoScale LONG $16_160 ' Pixel clock = 128MHz / 22 = 5.818181MHz VideoColorsOverlay LONG $0C_04_08_00 ' Modify if not using pins 18 & 19 for output VideoColorsOvrBlank LONG $04_04_04_04 ' Overlay value for blank video VideoColorsGen LONG $01_00_01_00 ' Modify if not usine pin 16 for output during generation LineTimerValue LONG 5120 ' 64uSec @ 80MHz SyncTimeOutValue LONG 1_600_000 ' ~1/10 second Next_Col LONG 768 ' Offset from one column to the next Next_Line LONG 16*768-4 ' Offset from line to the next (get subtracted) FlipBlackBit LONG $AAAA_AAAA ' XOR mask to make 0=transparent _syncPinMask LONG %0000_0000_1000_0000_0000_0000_0000_0000 ' Sync output from EL1883 IC P23 (22) _videoPinMask LONG %0000_0000_0000_1100_0000_0000_0000_0000 ' Video output from propeller (~470Ohm) P18,P196yhn 2 _videoSinkPin LONG %0000_0000_0000_0100_0000_0000_0000_0000 ' Video Sink (darken) pin mask P18 _genPinsMask LONG %0000_0000_0000_0011_0000_0000_0000_0000 ' Mask for both generation pins P16,P17 _genPinSyncMask LONG %0000_0000_0000_0010_0000_0000_0000_0000 ' Mask for generation sync pin P17 _overlayMode RES 1 ' 0=Overlay mode; 1=Generate mode _screenAddr RES 1 ' Address of screen array [8x192] longs _currentAddr RES 1 ' Address of current array element being drawn _dotPattern RES 1 ' Dot pattern of current element being drawn _videoActiveAddr RES 1 ' Address of video active variable in COG memory _videoActiveValue RES 1 ' 0=Video blanked; 1=Video active _palModeAddr RES 1 ' Address of PAL_Mode variable _palModeValue RES 1 ' Hold value in PAL_Mode variable 0=NTSC; 1=PAL generation _lineTimerCnt RES 1 ' Holds cnt value to start next line when generating _timeCnt RES 1 ' Used with WAITCNT to make delays _lineCnt RES 1 ' Current line of screen _horzCnt RES 1 ' Current long of current line _cargoAddr RES 1
So what i do is add the two lines
MOV _cargoAddr,par ' Get address of cargo ADD _cargoAddr,#12
to the main routine and than in the main loop i write the variable to the main ram with this line
WRLONG _overlayMode, _cargoAddr
Am i right to believe that that should be enough to read the _overlayMode value stored in cargo in the main program?
The mainprogram als should convert the _overlayMode value (which is a long right?) to a string value so i can display it on screen with the graphics method "text"
i hope i made myself clear so you understand:) and that someone has the time to take a look at the giant wall of code:P
Thanks in advance!
Comments
The memory location _cargoAddr is being calculated incorrectly. A multiple of #12 just feels wrong so I looked further.
The complier directive "RES" counts spaces as Longs so remember you add 1 for bytes, 2 for words and 4 for longs when calculating address locations. Below VideoFreq you also have 10 other LONGs defined then you have "cog" at the VAR section. Something is just not right. That #12 should be something more like 24 x 4 = 98dec
Would be a good exercise to create a 'GetAddress' PUB that hands off the address of _cargoAddr during runtime using the @_cargoAddr syntax.
When working with video displays, I will occasionally create a text line to show me where I am at runtime.
Jim-