Forum Discussion

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

genral software problem

im writing a simple clock program for a niosII standard processor and i encountered this bug

in my main loop i have an infinite loop which updates all the seven segments(DE2 board) like


while(1) {
      IOWR_ALTERA_AVALON_PIO_DATA(HEX2_BASE,sec_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX3_BASE,sec_10);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX4_BASE,min_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX5_BASE,min_10);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX6_BASE,hor_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX7_BASE,hor_10);
}
and the alt_u8 variables sec_1,sec_10 etc. are updated by a 100Hz interrupt(im running the processor on 50Mhz)

when i run the program the seven segments are not updated :(

but somehow this code works when i put a printf at the beggining of the while loop like


while(1) {
      printf(" ");
      IOWR_ALTERA_AVALON_PIO_DATA(HEX2_BASE,sec_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX3_BASE,sec_10);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX4_BASE,min_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX5_BASE,min_10);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX6_BASE,hor_1);
      IOWR_ALTERA_AVALON_PIO_DATA(HEX7_BASE,hor_10);
}
then it works perfect.. i tried replacing the printf with a simple while loop delay but that doesnt work either.

even when its not working the variables are updated timely and that means the process is running. but the code to update PIO_DATA works only when i put a printf

what could be the cause of this? please help..

could it be because of an include file which the compiler uses beacuse of printf? or is it a simple matter of a delay? if so why doesnt introducing a simple delay fix it

it also works when i put alt_printf

4 Replies

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

    I do not know why the display does not react well if no pause is given. The while could fail if the counter used is not declared as a volatile.

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

    You could try and declare the variables that your isr update as volatile. It will prevent the compiler from trying to optimise your code and will force a variable read at each IOWR call.

    I'm not sure this is the cause of your problem but you can always try.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Could well be.

    Without a function call (a call to any globally visible function should do) the compiler can/will cache all 'time' variables in registers.

    Marking them as 'volatile' will force the compiler to issue a memory read for each loop iteration.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    thanks :) im gonna have to wait till monday to try it out at uni cause i dont have a de2 board myself.. ill try making them volatile.. but if the compiler is caching those variables in registers instead of memory why wont those registers be updated within the interrupt function?