memory colision on a single byte
courtens
Posts: 101
Is this possible? Do it need a lock just for ONE byte?
I am using a byte to keep track if I am getting a PAL or NTSC video signal input - this is running in its separate cog. But as soon as I am running PWM_Nctrx object by Tracy Allen, also running in its separate cog, I am getting some strange behavior on my byte that holds that PAL or NTSC value.
Can anyone help?
I could provide more of the code, but it's messy and long.
Thanks !!!
I am using a byte to keep track if I am getting a PAL or NTSC video signal input - this is running in its separate cog. But as soon as I am running PWM_Nctrx object by Tracy Allen, also running in its separate cog, I am getting some strange behavior on my byte that holds that PAL or NTSC value.
Can anyone help?
I could provide more of the code, but it's messy and long.
PUB cog_motorPWM cog_motorPWM_COGID := COGID repeat PWM.PWMctrx2(motor_pin,motorspeed,testpercent) PUB cog_video | tmp, start_time, stop_time {{ detects video type (NTSC, PAL, or missing) signal input will return PAL_or_NTSC_value 0 for missing signal PAL_or_NTSC_value 1 for PAL PAL_or_NTSC_value 2 for NTSC }} cog_video_COGID := COGID repeat tmp:=cnt 'assign temporary time stamp 'to break out of repeat loop if not video signal is present repeat while ina[video_pin]==0 'hold at low if 6_000_000<(||(cnt-tmp)) quit 'brake out of repeat loop start_time:=cnt 'time stamp on just went high tmp:=cnt 'reassign temporary time stamp 'to break out of repeat loop if not video signal is present repeat while ina[video_pin]==1 'hold at high if 6_000_000<(||(cnt-tmp)) quit 'brake out of repeat loop tmp:=cnt 'reassign temporary time stamp 'to break out of repeat loop if not video signal is present repeat while ina[video_pin]==0 'hold at low if 6_000_000<(||(cnt-tmp)) quit 'brake out of repeat loop stop_time:=cnt 'time stamp on just went high again if stop_time>start_time 'read timer differance elapsed_time:=stop_time - start_time else elapsed_time:=(POSX - start_time)+(POSX + stop_time) if elapsed_time>3_300_000 PAL_or_NTSC_value:=0 'no video signal elseif elapsed_time>2_700_000 PAL_or_NTSC_value:=1 'is PAL else PAL_or_NTSC_value:=2 'is NTSC
Thanks !!!
Comments
-Phil
Would this be 1320 bytes / 4 = 330 long (?)
How do I assign space for that main (first) cog?
This the PWM_Nctrx object by Tracy Allen:
You don't. It's automatic.
Perhaps it would be best, at this point, to post your entire program. Just archive it, and attach the resulting zip file.
-Phil
The main issue is that two cogs can possibly access the storage unit at the same time. You can get into trouble if either of two (or more) cogs can change the value of the storage unit or if one cog reads the value of the storage unit twice expecting the value to be the same both times, yet another cog can change the value of the storage unit between the two times it's read. There are other variations of the problem, but these are the most common cases.
It's possible to have two cogs share a common variable if some rules are followed. This is the producer-consumer case which doesn't need a lock (semaphore). There's a good article in the Wikipedia on this.
Nothing in your code really sticks out as problematic. Only one method is setting PAL_or_NTSC_value, so no locks are necessary. Have you tried the program with the PWM module running but without a motor connected? I wonder if there might be motor noise coming in on the video input line.
-Phil
The problem starts appearing as soon as play_FW_pin or play_RW_pin goes high.
These some screen-shots that show how the array starts displaying misshaps.
Normal state - No video signal
Normal state - PAL
Normal state - NTSC
Problem appears as soon as I put play_FW_pin or play_RW_pin to high (array to the left starts showing new values outside of PAL or NTSC range)
This for PAL: value of 1596608 or 1599056 should not be there.
I was wondering if adding an extra cap would help prevent any bounces from occurring. I do have the signal go though a CD4066 switch with a 1M pull down resistor on the 3.3DCV side. On the other side (away form the propeller chip) I am sing LM1881 to give me ODD/EVEN for each video frame. That should be clean.
Never the less, I am using video input on P1 and motor output on P2 .... could that be causing the problem?
the noise is around 290mV but peeks up to 648mV at times -- right after it falls back to "0". I would need to check if a pull down would help keep the low lower.
I used a lock for my object for keypad scanning for the 74c92X chips.
I think it was the first thing I put in to stop clashes during memory reads and writes.
The bad news is that the error did not go away. I am still getting the same errors. It must be code related and must be somewhere in the cod_video section of the code.
The out shot: "repeat while" takes to little time to process -- and is prone of producing miss-reads with noisy signals.
I fixed it by adding a delay - waitcnt after my time stamp.
THANKS EVERYONE !