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.

Problems with Nigel's pic tutorial 2.2

Status
Not open for further replies.

charlie_r

Member
I'm just starting out with pic programming, and am having a problem with tutorial 2.2 from Nigel's series at WinPicProg.

Everything has worked correctly up to this point, with only 1 hardware issue, that has been dealt with.

A little background: As I don't have a ready source of veroboard, I am using a solderless breadboard for constructing the needed circuits. My programmer is a kitsrus K150 clone, sold as a pic+pro. For assembly of the code, I am using MPLAB.
I have been using p16F628A chips. Since the __config word supplied for the p16F628 <0x3D18> returns an error, I have set (using MPLAB) the __config word slightly different, to <0x3F10>.

MPLAB is constantly returning with "Message[302] E:\1STPROGWINPIC\TUTORIAL2\TUTORIAL2\TUT2_2.ASM 35 : Register in operand not in bank 0. Ensure that bank bits are correct."

With that said,on to the problem I'm having. In tutorial 2.2, the switches are supposed to turn LEDs on and off. This is not happening. First button push does turn the appropriate LED on, however subsequent button presses do nothing. I can turn any of the LEDs on, but unless I press another button to change which LED is lit, I cannot turn any of them off, as is supposed to be happening.

I have been told that all code supplied in the tutorials has been time tested to work, I am seriously wondering what could be causing my issues.

I have tried going on to 2.3, but am experiencing issues with that one as well. The patterns that are supposed to be going to the LED board from PORTB are not happening correctly. All I'm getting is the first 4 LEDs <RB0 - RB3> attempting to follow the patterns, with nothing showing up on <RB4 - RB7>

Voltage being supplied to the circuits is 4.95V± .02V, through an LM7805 regulator. Yes I have the capacitors on the 7805, and the decoupling cap on the power pins of the pic.

There is something else I'd like to do, as well as trying to find out the causes of these issues, is instead of sourcing to the LEDs, I'd like to sink from them. In other words, instead of active high, I'd like to make them active low. Or will that be covered in a later tutorial?

Sorry about the "wall of text", but I thought I would give you as much info as I could think of that might be relevant to my problem.

Thank you in advance for any help!
 
It works fine on my side

"Message[302] E:\1STPROGWINPIC\TUTORIAL2\TUTORIAL2\TUT2_2.ASM 35 : Register in operand not in bank 0. Ensure that bank bits are correct."
This is just a reminder to check banks and the 301 was just to tell you your using a 16f628a
 
Last edited:
Switches are wired as per Nigel's schematic. 10k pull-up resistor on the pin, lead to switch on the pin, other side of switch to ground. So there is a positive change in level from logic high to logic low on the pins. I have also double checked that all 4 switches are working properly, since the switches I am using are salvaged from old equipment (thanks for the tip, 3v0!).
 
I've just run tutorial 2.2 and I have the exact results as you do... This is what is supposed to happen SW1 will switch ON the LED1, SW2 will switch ON LED2 and extinguish LED1.. etc.. If SW1 is held down no other LED's will light.

I think you need momentary switches for this to work as is...

Ian
 
I've just run tutorial 2.2 and I have the exact results as you do... This is what is supposed to happen SW1 will switch ON the LED1, SW2 will switch ON LED2 and extinguish LED1.. etc.. If SW1 is held down no other LED's will light.

I think you need momentary switches for this to work as is...

Yes, you need momentary switches, not toggling ones - but I wasn't aware he was using toggling switches?.

Incidently, for the 628A the CONFIG value should be 0x2118.
 
The switches I'm using are momentary type tactile, 4 prong.

The problem, as stated in the OP, is that pushing the same switch a second time is not working as described in the write-up. I.E. turning off the led the switch controls.

I think I understand how the bit test f skip if clear / skip if set is supposed to work, but I'm not sure it is doing what it's supposed to.

Please correct me if I'm wrong with my description.
We press sw1, bringing pin RA7 low. the loop routine sees this, and sends the program out of the loop to Switch1. Debounce delay is called, then checked to see that it wasn't a transient drop out, meaning sw1 is still pressed. If it is, we are sent to check if the LED is lit, by checking the output of RA3. If that is high, we are sent to LED1OFF, which is supposed to [bcf LEDPORT, LED1] shut it off. If the LED is off (low at RA3), we go to LEDON, which sets the port high, passing current to light the led.

That is what is NOT happening for me. The LEDON is working, but not the LEDOFF on subsequent button presses of the SAME switch.

Or have I misunderstood the description of this section of the tutorial?


Will change the CONFIG and see if that helps.

EDIT:

Tried the 0x2118. No difference. However, have noted that this gives the same as 0x3F10 with only two differences -- the power on reset, and has a different checksum listed.

As mentioned in the OP, this is all being done on a solderless breadboard. Could that have an impact?
 
Last edited:
But according to the code, and the description, it is supposed to shut off the LED.

Or am I one of only a few that think this is what Nigel means by
Nigel said:
We then check to see if the corresponding LED is lit, with 'btfss SWPORT, LEDx', and jump to either 'LEDxON' or 'LEDxOFF', these routines are almost identical, the only difference being that the first turns the LED on, and the second turns it off.
 
Last edited:
That is true for tutorial 2.1 code description, I'm working with tutorial 2.2, description follows the code posting on Nigel's site.
 
Tutorial 2.2 - requires Main Board and Switch Board.

This program toggles the corresponding LED on and off, when the button opposite it is pressed. It introduces the concept of 'de-bouncing' - a switch doesn't close immediately, it 'bounces' a little before it settles, this causes a series of fast keypresses which can cause chaos in operating a device.

Code:
 insert code here

In order to de-bounce **snip**

We then check to see if the corresponding LED is lit, with 'btfss SWPORT, LEDx', and jump to either 'LEDxON' or 'LEDxOFF', these routines are almost identical, the only difference being that the first turns the LED on, and the second turns it off. **snip**
 
Ok will work on making a few perfboard versions.


Now I see how unreliable solderless breadboards can be at higher frequencies.

Once I got the switches off the board, onto a separate soldered up perfboard, it works as described. So was actually a hardware issue.

Thank you all for your help. You all made me read until I understood exactly what was going on, and how the code is supposed to do it's job.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top