Continue to Site

# PIC PortA and PortB not working the same.

#### Nigel Goodwin

##### Super Moderator
I'm using a PIC18F27K42, and part of the project requires an audio indication (beep), originally I had a piezo sounder across RA2 and RA3, bridged to make it louder. This worked perfectly well, but I was running low on I/O so thought - I'll move the piezo to RB6/RB7 instead (the ICSP pins) - and added header pins so I could connect or disconnect the piezo in case it wouldn't program with it there (and it wouldn't).

But, when I connect the piezo in circuit and the beep is called it makes a click and everything just locks up.

I've cured it by adding a 220 ohm resistor in series with the piezo, which also allows the ICSP to work - but I can't see any difference between PortA and PortB pins, so has anyone any ideas?. Doesn't really matter, because I've cured the issue - but I'm just puzzled about it?.

If anyone is interested?, I generate the 'beep' with a timer interrupt, set by this line:

Set_Beep(3, 100);

The 3 is one of a number of preset frequencies, done that way so I can alter the frequencies of a particular 'beep' all in one go (just alter the timer value that 3 refers to), and the 100 is the time of the beep in mS - you just call the routine and it runs transparently in the background.

#### tumbleweed

##### Active Member
Are you doing this with the ICSP connected?
Most programmers have a 4.7K pulldown on the ICSP clk and data lines.

Are you changing the PORTx reg or the LATx reg settings?
Show the couple of lines that twiddle the RB6/RB7 pins so we can see how you're doing it.

#### rjenkinsgb

##### Well-Known Member
But, when I connect the piezo in circuit and the beep is called it makes a click and everything just locks up.
Do you still have Debug mode selected, or production? I can imagine it messing up the debug data connection.

#### Nigel Goodwin

##### Super Moderator
Are you doing this with the ICSP connected?
Most programmers have a 4.7K pulldown on the ICSP clk and data lines.

Are you changing the PORTx reg or the LATx reg settings?
Show the couple of lines that twiddle the RB6/RB7 pins so we can see how you're doing it.

No, I unplug the programmer once it's programmed.

I use LATx, as below:

C:
// section from setup
#define TONE            LATBbits.LATB6      // output pin for beep
#define TONE2           LATBbits.LATB7      // output pin for bridged beep

// section from ISR
else if (PIR4bits.TMR1IF)
{
if (beep)
{
TONE = !TONE;
TONE2 = !TONE;      // for louder bridged output
}
else
{
TONE = 0;
TONE2 = 0;
}
PIR4bits.TMR1IF = 0; /* Clear Flag */
}

#### Nigel Goodwin

##### Super Moderator
Do you still have Debug mode selected, or production? I can imagine it messing up the debug data connection.
I never use debug

#### Nigel Goodwin

##### Super Moderator
Just check your IDE as it defaults to debug... There is a release/ debug combo box..
I hardly use release version..
I don't know where that might be?, and can't find it on MPLABX 6.0 - but all the hex files etc. are labelled as production, and the debug folder is empty.

#### tumbleweed

##### Active Member
Code:
#define TONE            LATBbits.LATB6      // output pin for beep
#define TONE2           LATBbits.LATB7      // output pin for bridged beep

TONE = !TONE;
TONE2 = !TONE;      // for louder bridged output
There's going to be a short amount of time where the IO pins are fighting each other, depending on what the compiler generates for that, and with XC8 it's quite a few instructions.

If you want them to toggle at the same time try something like:
Code:
LATB ^= 0xc0;

Electrically, all of those IO pins are spec'd the same so I can't see a difference from that end of things. I guess it just didn't like the direct load from the piezo for whatever reason.

#### Nigel Goodwin

##### Super Moderator
OH I see.... I haven't used MPLABX for some time... They have a menu for debug and a menu for production.... The little hammer icon has a dropdown menu...
Just had a luck, it still does

Debug is the second option down, the third one is Pro Comparison - presumably trying to sell you the expensive Pro compiler?.

#### Ian Rogers

##### User Extraordinaire
Forum Supporter
Remember! I have the pro version so Debug and production compile the same.. But I hardly ever use the programming pins, so I don't worry about that... I also don't use MPLAB, I use VSM inside Labcenter...
That has the button DEBUG / RELEASE...

Replies
3
Views
2K
Replies
4
Views
4K
Replies
6
Views
1K
Replies
4
Views
1K
Replies
7
Views
1K