PIC12F508 GPIO.2 Output problem

Hello I have written a simple program for a 12F508 in picbasic Pro to produce 190 Hz square wave on port pin GPIO.0, and I want the inverse of this to appear on GPIO.2. I get what I expect from GPIO.0, but nothing from GPIO.2. From the datasheet, I can see that the GPIO.2 pin is also for TOCKI, but it says it is a normal I/O pin also.

What am I doing wrong?

Cheers... Rob.

Reply to
Rob. Smith
Loading thread data ...

I haven't used that specific PIC, but check the _CONFIG word settings. Also check the datasheet to make sure that pin is not an open collector, in which case you'd need a pullup resistor.

Reply to
Anthony Fremont

I see nothing in the datasheet that would indicate you can not do this. What is missing here is information on how PICBASIC handles I/O and so on. Do you have to define the ins and outs? In other words, is the pin programmed to be an output. All pins are inputs by default. Is the software using a read/modify/write routine for the port and the port isn't being read as you expect? R/M/W commands are tricky on PICs that read the pins even if they are outputs. Make sure you have the pin hanging loose or pulled up by a 10K resistor or so AND NOTHING ELSE and see if the problem persists.

If all else fails, a schematic and program listing could be useful.

Reply to
WangoTango

Hello

Thanks for the reply. OK. To come clean, I am flashing LEDs on and off via a transistor in emmitter follower configuration, driven from GPIO.0 I have a tell tale output (following GPIO.0) on GPIO.1. I want the complement on GPIO.02. Both these outputs are connected via 100 Ohm resistors to a couple of BNC outputs. The output from GPIO.1 works perfectly.

Here is the program. Is it something stupid I am doing. I am not a programmer, but have managed to make a couple of projects work with PIC16C715 quite well.

*************************** INTRC_OSC ' This PIC has a 4MHz built in oscillator to use MCLR_OFF ' MCLR not required

' Inputs and outputs

Output GPIO.0 ' Output Pin 7 to drive the LEDs via a BC184L transistor Output GPIO.1 ' Output Pin 6 to provide a +ve logic sync pulse at 190Hz Output GPIO.2 ' Output Pin 5 to provide a -ve logic sync pulse at 190Hz Input GPIO.3 ' Not used so make an input for good measure Input GPIO.4 ' Not used so make an input for good measure Input GPIO.5 ' Not used so make an input for good measure

' Now for the main program

' First set the oututs Low to start

Low GPIO.0 Low GPIO.1 High GPIO.2

' Now go into a never ending loop to chop the outputs on and off at

190 Hz.

loop1:High GPIO.0 ' Turn output on to drive LEDs on

High GPIO.1 ' Turn output on to provide +ve TTL logic sync pulse

Low GPIO.2 ' Turn output off to provide -ve TTL logic sync pulse

Pauseus 2630 ' Pause this many microseconds with LEDs on

Low GPIO.0 ' Turn output off to drive turn LEDs off

Low GPIO.1 ' Turn output off to provide +ve TTL logic sync pulse

High GPIO.2 ' Turn output on to provide -ve TTL logic sync pulse

Pauseus 2630 ' Pause this many milliseconds with LEDs off

GOTO loop1 ' Do the above for ever.

' And if we crash badly and fall all the way out to here end it nicely

Low GPIO.0 ' Just in case we get here, better shut down the lights.

Low GPIO.1 Low GPIO.2

End

********************************* I was considering adding the line near the top.

OPTION_REG.5 = 0 ' Disable TOCS and T0CKI

To make sure that the the TOCKI was not overiding TRIS (whatever that is)

Any thoughts??

Cheers... Rob.

WangoTango wrote:

Reply to
Rob. Smith

That looks like it might do the trick. It seems that the OPTION register is set to 11111111 on power up and that would override the TRIS setting. I haven't played with the 508 in a while and I have never used PICBASIC, so I am just making educated guesses, but it is rare that a PIC comes up with anything that would over ride the TRIS setting turned on by default. It wouldn't hurt to give it a try.

Reply to
WangoTango

Hello Tried it today and it worked. I had a lot of trouble figuring out the exact line to use to set that bit. It seems a different way of doing it to the PIC16C715 I used before, where you can just state the name of the register = a number, where the appropriate number allows you to set or unset the various bits of the register to configure the chip. Anyway, after some detective work, I got a configuration setting that would compile without errors, and away we go.

Thanks for all the help. With regards to PicBasic Pro (PBP). Like I say, I am not a software engineer, but at the time, a PIC offered a convenient way to achieve my requirements. Added to that, we all have done a little basic programming over the years (at school for me), so we found that PBP was easy enough and powerful enough to go with. If I had to do it in the PIC assembly language (or C for that matter), I'm afraid it would be somebody else who would be working (and struggling) with it.

Cheers... Rob.

Reply to
Rob. Smith

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.