Forum Discussion

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

Direct access to pins

Hello you all! http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif

I&#39;ve just begun playing with Nios Development Kit - Cyclone Edition. I&#39;m using the count binary tutorial to do my tests. Now I would like to generate a square wave on a pin on J11; let&#39;s say pin 39, connected to pin PIN_J16 of the 1c20. I think I&#39;ve to do the following steps:

1. in sopc builder, I&#39;ve to add a new PIO module.

2. in the bdf, I bind the pio output to pin j16

3. in the software, I&#39;ve to write something to set and reset the pin.

Are these steps correct? And about step 3, how do I set and reset the pin in C?

Thanks in advance!

My regards,

Marco Lazzaroni

4 Replies

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

    I think it&#39;s simpler to generate a square wave in hardware using only the second step you&#39;ve written (and eventually adding a clock divider/multiplier)...

    I think it&#39;s more correct too, because a sqare wave generated by software it&#39;s not reliable... (and it&#39;s the first time I&#39;ve heard it) http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/wink.gif

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

    > Are these steps correct?

    yes :-)

    > And about step 3, how do I set and reset the pin in C?

    Just define a pointer to the &#39;data&#39; register and write the data you want.

    If your&#39;re using data cache, you may want to set bit 31 of the address.

    unsigned long *p = (unsigned long *) 0xSOMEADDR;

    ...

    for (;;) {*p = 1; *p = 0;}

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

    To generate a square wave, you can use a counter with a compare tacked on. Adjust the compare value to change the duty cycle, and change the value that gets loaded into the counter to adjust the frequency (so you have 2 registers sitting outside of the NIOS to control the wave generation, and around 20-40 LEs of hardware for the wave generation). You will have to figure out duty cycles based on the frequency since you are loading clock cycles and not Hz into this thing, but that&#39;ll just be simple math (multiply and divide).

    I have seen software based generation, however you will not be clock cycle accurate if you take that route so I would splurge and use up logic to make one in hardware (you can make it accurate to within one clock cycle).

    Cheers.