Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17255 Discussions

LED no reaction after successfully loading lights.c into the cyclone II

Altera_Forum
Honored Contributor II
1,273 Views

Hi, guys, 

 

Thank to the previous help from you, finally I managed to load the c program into the cyclone II using Altera Monitor Program without any error message.... 

 

The program is as follows: 

 

#define switches (volatile char *) 0x0001800# define leds (char *) 0x0001810 

void main() 

{ while (1) 

*leds = *switches; 

} 

 

 

it is supposed to "load the addresses of the Data registers in the two PIOs into processor registers r2 and r3. It then has an infinite loop that 

merely transfers the data from the input PIO, Switches, to the output PIO, LEDs." according to the sopc introduction tutorial... 

 

however, the no matter how i tilt the switches on the board, the LED never turns on! 

 

How could this be? 

 

Thanks and regards
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
506 Views

Please grit, ask your questions in only one thread at a time. Either put all your questions in one thread, or create a new thread for each question, but do not post them in multiple places. It makes it very difficult to follow up. 

 

What you are facing is probably a cache problem. The first time the CPU reads the switches value, it is put in its data cache. Then the other times the CPU will read the cached value instead of the one from the switches. One way to get around this is to uso the IORD/WR macros: 

 

(not compiled/tested, but the basic idea is there) 

 

#include <io.h> # define SWITCHES 0x0001800 # define LEDS 0x0001810 void main() { while (1) IOWR(LEDS,0,IORD(SWITCHES,0)); }  

 

Or even better, to use the dedicated PIO macros: 

#include "altera_avalon_pio_regs.h" # define SWITCHES 0x0001800 # define LEDS 0x0001810 void main() { while (1) IOWR_ALTERA_AVALON_PIO_DATA(LEDS,IORD_ALTERA_AVALON_PIO_DATA(SWITCHES)); }  

 

Also check that the addresses that you put in the defines match the ones in your SOPC system. You should use the *_BASE constants that are automatically generated for you in system.h, it will same you some time and trouble.
0 Kudos
Altera_Forum
Honored Contributor II
506 Views

 

--- Quote Start ---  

Please grit, ask your questions in only one thread at a time. Either put all your questions in one thread, or create a new thread for each question, but do not post them in multiple places. It makes it very difficult to follow up. 

 

What you are facing is probably a cache problem. The first time the CPU reads the switches value, it is put in its data cache. Then the other times the CPU will read the cached value instead of the one from the switches. One way to get around this is to uso the IORD/WR macros: 

 

(not compiled/tested, but the basic idea is there) 

 

#include <io.h> # define SWITCHES 0x0001800# define LEDS 0x0001810 void main() { while (1) IOWR(LEDS,0,IORD(SWITCHES,0)); } Or even better, to use the dedicated PIO macros: 

#include "altera_avalon_pio_regs.h" # define SWITCHES 0x0001800# define LEDS 0x0001810 void main() { while (1) IOWR_ALTERA_AVALON_PIO_DATA(LEDS,IORD_ALTERA_AVALON_PIO_DATA(SWITCHES)); } Also check that the addresses that you put in the defines match the ones in your SOPC system. You should use the *_BASE constants that are automatically generated for you in system.h, it will same you some time and trouble. 

--- Quote End ---  

 

Hi, Daixiwen, 

 

sorry about the thread posting...I will put all my questions in one post next time... 

 

Your code works on my board! and the LEDs are now reacting accordingly.  

 

Thanks a million!
0 Kudos
Altera_Forum
Honored Contributor II
506 Views

@grit 

 

 

 

the problems are due to the caching of the data. The information is only written in the cache and not forwarded to the IO. You could solve your problem either by adding the attribute "volatile" to your IO variable as such: 

 

#define Switches (volatile char *) 0x0001800# define LEDs (volatile char *) 0x0001810 void main() { while (1) *LEDs = *Switches; } 

 

or by following the suggestions by Daixiwen. 

 

Hope this helps...
0 Kudos
Altera_Forum
Honored Contributor II
506 Views

 

--- Quote Start ---  

@grit 

 

 

 

the problems are due to the caching of the data. The information is only written in the cache and not forwarded to the IO. You could solve your problem either by adding the attribute "volatile" to your IO variable as such: 

 

#define Switches (volatile char *) 0x0001800# define LEDs (volatile char *) 0x0001810 void main() { while (1) *LEDs = *Switches; } 

 

or by following the suggestions by Daixiwen. 

 

Hope this helps... 

--- Quote End ---  

 

 

Hi, Sanmao, Thanks a lot for your adivce. I will try that out. =)
0 Kudos
Reply