- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You might be reading a cached value of trigger_reg if you have data cache turned on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How would I implement an interrupt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I wouldn't debug with printf. This takes a long time and may result in missing the pulse.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
erm... printf is for basic way, any better suggestion which is more easier and faster?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Leds? This could be done in a few processor instructions, but you need them in your project...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i guess, when we do not know where goes wrong, probably print f in every occasion is the only option you can try already...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is some information from altera on interrupts and exception handling
https://www.altera.com/ja_jp/pdfs/literature/hb/nios2/n2sw_nii52006.pdf- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
first of all is this a Nios II or SOC? as the interrupt procedure may works differerenly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You should implement this circuit in hardware - verilog or vhdl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page