How fast should this be executing?

Discussion in 'Embedded Systems and Microcontrollers' started by wannaBinventor, Sep 13, 2010.

  1. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    I'm running a PIC 16F818 at 4mhz with the internal oscillator. I've got a keypad and an LCD connected and it seems like it is running very slowly. In fact, the LCD always seems to run slowly.

    For instance, I'll hit a button once I come to a point in the prog (not on the keypad, just a simple pushbutton) that will take me into a call for a keypad scanning routine on a 4x3 matrix keypad. The LCD will then display "enter first number" and once that is entered it will display "enter second number" on the next line. It probably takes at least a second to two seconds (maybe more) from the time I press and release the button to the time I see something happening on the LCD. I have 0.1 second delays following the BTFSC and BTFSS commands for debouncing each switch, but that only accounts for .2 seconds. What is taking everything else so long?

    I don't have a scope but I know the internal oscillator is set to 4MHZ or else it wouldn't have been correctly measuring some pulse widths I had on a recent IR project.

    The LCD is a 20x2 HD44780 based display.

    I'm also sure it's not this program because in some of my programs I'm doing math with the PIC (like a 30 something instruction cycle division routine) and I'll have it display "answer is" on the LCD and then use a LU table to generate the proper number to display. It seems in this case I'll get "Answer is" and then a second or more after it will fill in my number.

    Is this normal for these PICs and LCDs?
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I think you are going to have to post code. Especially the oscillator setup and the debouncing part. It doesn't sound normal. 818 has a variable speed oscillator which defaults to 31.25KHz.
     
  3. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4

    I'll grab the code and post if when I get home. I'd imagine its correct, however, b/c I know I have some second long delays (actually three of them together) where an LED is lit, and that actually seems to be 3 seconds.

    Thanks for the reply.
     
  4. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    When I went to post the code I noticed a very dumb mistake.

    I have 0.1 sec delays all over the place for debouncing and what not. When I went to post the code I noticed that I didn't give the return command after the .1 sec delay. The 1 sec delay is right after it in the code so everytime I called a .1 sec delay I was actually calling a 1.1 sec delay.

    Sorry to waste your time.

    What really gets me about programming is how you can spend an hour and a half writing a few hundred lines of code and then spend just as long figuring out that you forgot one little line.

    Thanks
     
    Last edited: Sep 14, 2010
  5. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    It's happened to us all. I'm sure that's why I always put return straight after I declare the function, then fill in the gap. Unfortunately there are always new bugs that creep in, and ones you forgot about.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The best programmers do not only master programming. But also debugging. If you use MPLAB you can track down many errors using the software simulator. And if you have at least a PICKIT unit, you can do hardware debugging. If your chip support this of course. So it is very important to learn how to do single stepping, setting breakpoints, using stimulus etc. As those are your best friends then it comes to programming
     
  7. wannaBinventor

    Thread Starter Member

    Apr 8, 2010
    179
    4
    I am going to have to learn more of that.

    I can do some MPLAB SIM but only the most basic features. Breakpoints never seem to work in MPLAB SIM for me. I was also trying to set an interrupt flag in the simulator last night, but couldnt figure out how to do it in the stimulus window. I've never even tried ICD, so it sounds like I need to get with the program.

    Thanks
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
Loading...