Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Direct access to pins

Altera_Forum
Honored Contributor II
1,398 Views

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
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
461 Views

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!
0 Kudos
Altera_Forum
Honored Contributor II
461 Views

> 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
0 Kudos
Altera_Forum
Honored Contributor II
461 Views

Thank you both for your useful replies http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif  

 

I think I&#39;ll follow Scott&#39;s advice since at the moment I&#39;m focused on getting direct access to pins. 

Thank you again :-)
0 Kudos
Altera_Forum
Honored Contributor II
461 Views

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.
0 Kudos
Reply