Altera_Forum
Honored Contributor
19 years agoNios II Evaluation Board "not responding"
Hi guys, I am using the Nios II IDE to implement some C++ code that controls a VFD on a Nios II Evaluation Board. I've gotten it to work pretty well, it displays whatever I want. However, the FPGA seems to stop operating after 5 to 10 minutes in an infinite while loop. My code is as follows.
#include <stdio.h># include "system.h"# include "altera_avalon_pio_regs.h"# include "string.h"
void chr_wr(int code);
void put_txt(int x,int y,unsigned char *text,int textlen);
void set_position(int x,int y);
void disp_clear(void);
int read_data(void);
void write_data(int dat);
void write_cmd(int cmd);
void wait_ms(long time);
void brightness(int br); //0 for 100%, 1 for 75%, 2 for 50%, 3 for 25%. Must be 2nd instruction after function_set.
void set_udf(int code,int *data);
void init_vfd(void);
void function_set(int bus_width); //1 for 8-bit, 0 for 4-bit. Must be first instruction sent after power-on
void entry_mode_set(int inc_dec, int shift); //1 for inc and 0 for dec, 1 for display shift and 0 for cursor shift
void display_on_off(int display, int cursor, int blinking); //1 for on 0 for off
const int udf={{0x1f,0x11,0x11,0x11,0x11,0x11,0x1f,0x00},
{0x00,0x0e,0x0a,0x0a,0x0a,0x0e,0x00,0x00},
{0x00,0x00,0x04,0x04,0x04,0x00,0x00,0x00},
{0x00,0x0e,0x0a,0x0a,0x0a,0x0e,0x00,0x00}};
int main()
{
int i=0;
printf("VFD Controller Test - Remotec\n");
init_vfd();
put_txt(4,0,"Jason Kientz",12); // text
put_txt(5,1,"= Ballsack",10);
//put_txt(0,0,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_=+",40);
//put_txt(0,1,"abcdefghijklmnopqrstuvwxyz!@#$%^&*() <>.",40);
set_position(0,0);write_data(0x01); // udf 0x01 in each corner
set_position(0,1);write_data(0x01);
set_position(19,0);write_data(0x01);
set_position(19,1);write_data(0x01);
while(1) // cycle udf's
{
set_udf(0x01,&udf);
wait_ms(100);
i++;
if (i==4)
i=0;
}
//write_cmd(0x3FF);
return 0;
}
/********************************************************************************
*****************/
/* Function descriptions :- */
/* */
/* init_h8 - Sets up H8 port directions */
/* chr_wr - Places a single char at the current ddram location */
/* put_txt - Writes a text string starting at col x,row y */
/* set_position - Sets ddram location (cursor position) to x,y */
/* disp_clear - Clears screen */
/* read_data - Reads data from the module (at current position) */
/* write_data - Sends a data byte (CD low) */
/* write_8bit_data - Sends a data byte with only 1 'e' strobe (CD low) */
/* write_cmd - Sends a command byte (CD high) */
/* write_8bit_cmd - Sends a command byte with only 1 'e' strobe (CD high) */
/* wait_ms - Waits for specified number of milliseconds */
/* brightness - Sets the specified brightness (0-3) */
/* set_udf - Loads data into a single udf char */
/* init_vfd - Initialise VFD */
/* */
/********************************************************************************
*****************/
void chr_wr(int code)
{
write_data(code);
}
void put_txt(int x,int y,unsigned char *text,int textlen)
{
int a;
set_position(x,y);
for(a=0;a<textlen;a++)
{
chr_wr(text); /* write text a character at a time */
}
}
void set_position(int x,int y)
{
write_cmd(0x80+x+0x40*y);
}
void disp_clear(void)
{
write_cmd(0x01);
wait_ms(30);
}
int read_data(void)// MAY NOT WORK - CHECK ON HOW TO WORK WITH BIDIR PINS
{
int result;
write_cmd(0x300);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 1);
result=IORD_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 0);
write_cmd(0x00);
return(result);
}
void write_data(int dat)
{
dat += 0x200;
IOWR_ALTERA_AVALON_PIO_DATA(LCD_PIO_BASE, dat);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, dat);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 0);
wait_ms(1);
}
void write_cmd(int cmd)
{
IOWR_ALTERA_AVALON_PIO_DATA(LCD_PIO_BASE, cmd);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, cmd);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 1);
IOWR_ALTERA_AVALON_PIO_DATA(LCD_E_PIO_BASE, 0);
wait_ms(1);
}
void wait_ms(long time)
{
usleep(time*1000);
}
//0 for 100% brightness, 1 for 75%, 2 for 50%, 3 for 25%
void brightness(int br)
{
int value = 0x200;
if (br == 1) value += 0x01;
else if (br == 2) value += 0x02;
else if (br == 3) value += 0x03;
write_cmd(value);
}
void set_udf(int code,int *data)
{
int a;
write_cmd(0x40+code*8);
for(a=0;a<8;a++)
{
write_data(data);
}
}
void init_vfd(void)
{
function_set(1);
wait_ms(10);
brightness(0);
entry_mode_set(1,0);
display_on_off(1,0,0);
disp_clear();
}
//1 for 8-bit, 0 for 4-bit. Must be first instruction sent after power-on
void function_set(int bus_width)
{
int value = 0x20;
if (bus_width == 1) value += 0x10;
write_cmd(value);
}
//1 for inc and 0 for dec, 1 for display shift and 0 for cursor shift
void entry_mode_set(int inc_dec, int shift)
{
int value = 0x04;
if (inc_dec == 1) value += 0x02;
if (shift == 1) value += 0x01;
write_cmd(value);
}
//1 for on 0 for off
void display_on_off(int display, int cursor, int blinking)
{
int value = 0x08;
if (display == 1) value += 0x04;
if (cursor == 1) value += 0x02;
if (blinking == 1) value += 0x01;
write_cmd(value);
}
/* ************************************************************************* */
/* ***************** 12.Pin Assignment ************** */
/* ***************** 12.1 Signal Connector. ************** */
/*---------------------------------------------------------------------------*/
/* */
/* (parallel# 1 ) 12.1 CU20025ECPB-U1J Signal Connector */
/* */
/*---------------------------------------------------------------------------*/
/* Pin Signal Pin Signal */
/* 1 GND 2 VCC */
/* 3 FNC 4 RS (P66) */
/* 5 RW (P65) 6 E (P64) */
/* 7 D0 8 D1 */
/* 9 D2 10 D3 */
/* 11 D4 (P60) 12 D5 (P61) */
/* 13 D6 (P62) 14 D7 (P63) */
/* */
/* Note : 4 bit mode */
/*****************************************************************************/ Has anyone else ever had a problem like this. It has something to do with the FPGA not responding because if I try to download the software onto the board again before it locks up it works fine, but if I try to download the software onto the board after it locks up it gives me the following message Using cable "Nios II Evaluation Board ", device 1, instance 0x00
Pausing target processor: not responding.
Resetting and trying again: FAILED
Leaving target processor paused Im wondering if I have some sort of setting wrong or if I have some kind of memory leak. Im not sure. Any help would be appreciated. Thanks, Sean