Forum Discussion

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

Issue of PS/2 IP core

I have implement a porgram which show the key from keyboard on VGA, but now i meet a trouble. it show twice character whenever i press the keyboard. I try to set a breakpoint at the condition if (decode_mode == KB_ASCII_MAKE_CODE );, then everything work properly. But when I remove the break point it show the character twice.

Can any one advice this? Thank you

#include "system.h"# include "stdio.h"# include "altera_up_avalon_character_buffer.h"# include "altera_up_avalon_pixel_buffer.h"# include "altera_up_avalon_ps2.h"# include "altera_up_ps2_keyboard.h"
 
/*Function that read keyboard input and show on monitor*/
void read_keyboard(alt_up_ps2_dev *ps2_kb, alt_up_char_buffer_dev  *vga)
{
    KB_CODE_TYPE decode_mode;
    alt_u8 buffer;
    int x = 0, y = 1;  //If y start from 0 character will hide on the top of monitor
    char ascii;
    char *inputStr;
    alt_up_char_buffer_init(vga);
    alt_up_char_buffer_clear(vga); //Clear previous character on the screen
 
    while(1) 
    { 
        if (decode_scancode(ps2_kb, &decode_mode, &buffer, &ascii)==0) //If get a make code from keyboard
        {
                if (decode_mode == KB_ASCII_MAKE_CODE );
                {
     translate_make_code(decode_mode, buffer, inputStr); //translate the code like "SPCAE", "BACKSPACE"
     alt_up_char_buffer_string(vga, inputStr, x,y);
     x++;
     if (x > 80)
     {
      y++;
      x = 0;
     }
     if (y > 60)
     {
      y = x = 0;
     }
    }
        }
    }
}
 
int main(void)
{    
 
    alt_up_ps2_dev *ps2 = alt_up_ps2_open_dev("/dev/up_avalon_ps2_0"); //open PS/2 device
    alt_up_ps2_init(ps2);
    alt_up_ps2_clear_fifo(ps2);
    alt_up_char_buffer_dev  *vga = alt_up_char_buffer_open_dev("/dev/up_avalon_character_buffer_0");//open vga device
 
 
   if (ps2->device_type == PS2_KEYBOARD) //Check if the device connected to PS/2 is keyboard
    {
 
        read_keyboard(ps2, vga);
    }
    else 
    {
        printf("Error...\n");
        return -1;
    }
 
 
 
} 

6 Replies

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

    I am having this same problem. I'm also calling decode_scancode() in a while(1) loop, and it always gives me to make codes (press and release), never any break codes.

    Anyone else have this issue? My code is essentially the same as ctkhai's

    Regards,

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

    Hi all, where did you get altera_up_avalon_character_buffer.h?

    I am not finding this file in my PC at all.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    @waiyung, Do you have the University Program IP packages installed? Anything with "_up" in it is referring to University Program.

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

    By the way, all, this is definitely some sort of timing issue. I too got it to work while debugging and stepping through the program, but not running at full 16MHz. I wondering if its managing to pull the same code from the buffer twice before it is cleared or something. I know it's not elegant, but inserting some sleep (somewhere, I can't remember now) did the trick.

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

    Yes, I have UP package installed. But it does not have the header file altera_up_avalon_character_buffer.h

    I double checked it by searching through my PC. This file is not there. But I found altera_up_avalon_video_character_buffer_with_dma.h

    Also, in the system file, I cannot find the character_buffer either. Any idea?