Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC mad loop but not in simulation

Status
Not open for further replies.

throbscottle

Well-Known Member
First off, Merry Almost-Christmas everybody!

I've got a 16F57 (dinosaur, I know) to accept numbers and functions from a keypad and also read a rotary encoder. It displays the value on a VFD. Mostly works very nicely, but I get this strange behaviour that I can't cause in the simulator.
It has functions to increment or decrement individual digits) or the whole value or display brightness using the arrow keys. The rotary encoder can hijack these functions to perform the same function, only really quickly. A function key sets/clears a flag bit to enable or disable the encoder.
What actually happens is that if the rotary encoder is set to any output other than 00, the program goes into an uncontrolled countdown. When I had it so it wasn't doing this it was madly zipping the cursor across the screen.
It doesn't appear to be related to any noise being picked up, bouncing contacts or anything like that. It looks as if the code is going to an incorrect address, or picking up the wrong variable, but only doing it in the physical PIC, not the simulator. All the bank and page bits are being set correctly as far as I can see.
Anyone seen something like this before? Suggestions (not "get a newer PIC" please!) Please!

Thanks in advance
 
Eeek! Aaargh! Ignore me.
It does it if I set the port pins using stimulus instead of the variable list. Onwards and upwards...
 
It sounds rather like you are using the two inputs as increment and decrement at every scan, rather than only once when there is an appropriate change of state?

If you are using a "previous state" variable, is that getting messed up somehow?
 
You almost hit the nail on the head. Once I'd started to use the simulator correctly, I found a banksel I'd commented out because I thought it didn't need it and then forgot about (because I was fixing another bug), so it was failing to write the state at all.
And yes, at the end of every keypad scan, it scans the encoder, updates the display, checks tactile switch inputs and updates LEDs (these last 3 things being run by the PT6315 VFD driver)
However it does detect change of state in the encoder so it doesn't get as far as the up/down routines if nothing happened (which now works correctly). I don't see a way to do it without actually reading and comparing the encoder values though (event-driven things not being an option)

Thanks for the response - appreciated.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top