How fast should this be executing?

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
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?
 

Markd77

Joined Sep 7, 2009
2,806
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.
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
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.

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.
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
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:

Markd77

Joined Sep 7, 2009
2,806
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.
 

t06afre

Joined May 11, 2009
5,934
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
 

Thread Starter

wannaBinventor

Joined Apr 8, 2010
180
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
 
Top