Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12435 Discussions

Problem with IORD_ALTERA_AVALON_PIO

Altera_Forum
Honored Contributor II
885 Views

hi, 

i want to write a simple code witch can turn on a led when i press a button. 

i have write this piece of code but seems doesn't works... 

 

here is my code: 

 

int main() { volatile long BOUTONS_ON; while(1) { BOUTONS_ON = IORD_ALTERA_AVALON_PIO_DAT(KEY_LINE_BASE); if ((BOUTON_ON & 0x1) == 0x1) { Led2_ON(); } else { Led2_OFF(); } } return 0; }  

the build works but  

the instruction seems to be always true Led2 is always turned ON. 

maybe i have missed something or my code must be writted diffrently
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
148 Views

As a first check I's swap the ON/OFF over - and see if the led is now off! 

That should let you find out whether the problem is with the leds or switch. 

 

As written you'll need to be holding down the switch to have any effect. 

 

You might also try a software delay loop inverting the led after each delay.
Altera_Forum
Honored Contributor II
148 Views

Change if ((BOUTON_ON & 0x1) == 0x1) to 

 

if (BOUTON_ON > 0)
Altera_Forum
Honored Contributor II
148 Views

with your test waiyung it will be always Wrong. 

i give you my source code maybe you will see something wrong: 

http://sega4ever.power-heberg.com/fpga/test2.rar
Reply