- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hi,
I'm trying to implement a counter that counts down when it recieves a trigger pulse from the hardware (in this case, it's a short burst of AC, in the order of a few hundred µs), which keeps an LED on. I have no idea why my code isn't working, I'm pretty new to C programming. Any help greatly appreciated.if (trigger_reg == 1){ //goes to 1 when the AC signal reaches the trigger module threshold
int countdown = 10000000; //arbitrary value
while (countdown > 0){ //use this loop to keep the LED on longer than the trigger pulse, so the user can see it
green_leds=1;
countdown--;
}
} else {
green_leds=0;
}
-N
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I assume this code is placed in a while loop, and you are polling the trigger_reg. However, if your burst is short, then your polling is simply missing the trigger. You should be using interrupts.
Better yet, you should implement this circuit in hardware - verilog or vhdl.- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
You might be reading a cached value of trigger_reg if you have data cache turned on.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hi,
Probably may need to simplify to basic functional code test first, if the basic one work then can implemented your target purpose. Example you can place more printF and print all the related condition if and else entry/ variable (trigger_reg[11]) to have a closer look how your program runs.- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I wouldn't debug with printf. This takes a long time and may result in missing the pulse.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
erm... printf is for basic way, any better suggestion which is more easier and faster?
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Leds? This could be done in a few processor instructions, but you need them in your project...
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
i guess, when we do not know where goes wrong, probably print f in every occasion is the only option you can try already...
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Here is some information from altera on interrupts and exception handling
https://www.altera.com/ja_jp/pdfs/literature/hb/nios2/n2sw_nii52006.pdf- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
first of all is this a Nios II or SOC? as the interrupt procedure may works differerenly
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
A wild guess here.
Compile with no optimization at all. The optimizer may be shrinking all the code to almost nothing if the variables are not declared volatile.- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
You should implement this circuit in hardware - verilog or vhdl.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
--- Quote Start --- You should implement this circuit in hardware - verilog or vhdl. --- Quote End --- What if the OP wants to make a bigger design and this is just a first step? Yes a HDL solution would work, but you need to be able to understand the languages and hardware design, which not everyone does or wants to invest in.
