계수 모듈을 실현하려고합니다. 내 기본 설정 : 신호 발생기에 연결된 IO 포트에 연결된 2 개의 BNC 케이블과 판독을 위해 USB / UART를 통해 PC에 연결된 FPGA (Digilent의 Arty with Xilinx Artix-35T). 내 신호 발생기는 1Hz의 TTL 신호를 생성합니다.
이제 채널 1, 채널 2의 이벤트 수와 채널 1과 2의 일치를 계산하려고합니다. 기본 원리가 작동하는 동안 채널 1과 2가 동일한 입력 (BNC- T 커넥터). 또한 때때로 출력 채널 중 하나가 어느 방향 으로든 점프합니다 (그림 참조). 보라색 채널 ( "채널 1")은 녹색 ( "채널 2")과 다른 기울기를 갖습니다. 또한 우연의 일치는 여기서 두 개의 작은 손실 점프를 만듭니다.
내 순차 계산 코드는 다음과 같습니다.
reg [15:0] coinciInt [(numCoincidences -1):0]; // internally store events
always @(posedge clk or posedge reset) // every time the clock rises...
begin
signalDelay <= signal; // delayed signal for not counting the same event twice
if(reset) // reset
begin
for(i=0;i<numCoincidences;i=i+1)
coinciInt[i] <= 16'b0;
end
else // No reset
begin
for(i=1;i<numCoincidences;i=i+1) // loop through all coincidence possibilities:
begin
if( ((signal & i) == i) && ((signalDelay & i) != i) ) // only if signal give coincidence, but did not give before, it's a coincidence
begin // "(signal & i) == i" means that "signal" is checked if bitmask of "i" is contained:
// ((0011 & 0010) == 0010) is true, since 0011 & 0010 = 0010 == 0010
coinciInt[i] <= coinciInt[i] + 1'b1; // the i-th coincidence triggered, store it
end
end
end
end // end of always
assign coinci = coinciInt; // the output variable is called coinci, so assign to this one
Please note that all events are in the register coinci - coincidences as well as 'single events'. Ideally, coinci[1] should store events of channel 1, coinci[2] these of channel 2 and coinci[3] coincidences between 1 and 2, since channels are labelled by 1,2,4,8,...,2^n and coincidences by the respective sum. coinci[0] is used for some kind of checksum, but that's off-topic now.
Are there any ideas for the missing counts? For the different slopes?
Thank you very much
Edit 1
@Brian Magnuson pointed to the meta stability issue. Using multi-buffered inputs solved the issue of diverging channels. That works nicely. Although I don't fully understand the reason for this, I also did not see any jumps in the coincidence channel so far. You probably save me a lot of time, thanks!
메타 안정성 문제가 의심됩니다. ch1 / ch2에서 들어오는 펄스가 사용중인 시스템 클럭과 동기화되지 않았을 수 있습니다. 여기를보십시오 .
이 때문에 예상치 못한 동작을 일으키는 카운터 업데이트 '중간'을 포착하는 경우가 있습니다.
이 문제를 해결하기 위해 나머지 로직에 입력하기 전에 입력을 두 번 (듀얼 랭크 싱크로 나이저라고 함) 할 수 있습니다. 일반적으로 다중 비트 동기화에는 좀 더 신중한 처리가 필요하지만 귀하의 경우에는 각 비트를 독립적으로 처리 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다