Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

Trigger and counter.

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

13 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You should implement this circuit in hardware - verilog or vhdl.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- 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.