PDA

View Full Version : PIC12F629 or 8pin



andyf
- 24th October 2004, 14:18
Has anyone used a PIC12F629 for a successfull project, or does anyone recommend an 8pin microcontroller that is as easy to use as the 18pin PICF84

The project I am trying to do needs a really really low cost Flash programmable microcontroller that can sit looking for a specific serial ASCII code string and when it sees the string it will enable one or more outputs on the PIC for 1 seconds then turn it off again. The output bit than is enabled needs to also switch a low power relay that in turn will supply power to a 12Volt DC lamp.

I use Pic Basic V2.03 and an Epic LPT programmer.

Anyone fancy helping me with the project, I am sure for some this is like very easy, for me its a nightmare and I really would welcome some help.


Andy

Melanie
- 24th October 2004, 21:32
Is this the PICBasic Pro compiler?

If it is, your version is so old that support for the newer PICs like the 8-pin 12F675 which I would have recommended is non-existant, quite apart from the heaps of bug fixes that have happened along the way. There's issues with 16F628 even if you build your own support files.

Invest in an upgrade, it's only a few dollars... then we can play ball, safe in the knowledge that theres a likelyhood of success.

mister_e
- 25th October 2004, 03:26
Hi andyf,
Since V2.03 is certainely not a regular Melabs PIC Basic version, you have off course PICBasic Pro compiler. In this case Melanie's right on that upgrade option.

Some chips like 12f625,12f675,12f683,16f628,16f877.... have internal analog comparator AND OR analog to digital converter, if you don't turn them off when you don't need them, you will experiment errors.

It's a common problem for a lot of person and asked offen on every forum and well explain on all compiler's provider but, it seems that often, all these discussion have'nt be read or take in consideration.

But see those PIC12FXXX tips. I assume that you don't know them.

turn off analog comparator on PIC12F629

CMCON = 7

turn off analog comparator & analog to digital conveter on PIC12F675

CMCON = 7
ANSEL = 0

Once again, you must read everytime each datasheet on each and every PIC you'll use. PIC12F629 is a good and cheap 8 pins PIC. If you don't need any analog stuff, you can also use PIC12C508. In this case you'll need a few UV EEPROM version for experiment, UV eraser, and patience + OTP for the final product.

It seems that Microchip produce now a FLASH version of PIC12C508 : PIC12F508 but also seems to be not in stock for many parts distributor for now.

regards

andyf
- 25th October 2004, 12:35
Hi Melanie,

I thought my version would be well old by now, anyway I am at this point trying to choose the right PIC for the application, then choose a programmer that supports the PIC, dont reallt need one that suports all PIC's.

Upgrading to a new version is a good idea too, one problem is I dont think I have the original order anymore as a friend ordered it for me and mailed the order confirmation which I dont think I have either, one additional complication, he has moved and I am no longer in contact with him. He ordered both the LPT Epic and software at the same time.

I dont think I can get the upgrade like this can I, and am not really prepaired to pay again when I could maybe find an alternative that will just do the one PIC i need it for.

Am really trying to find a suitable PIC to do what is really a simple task, using a PC to simulate it is.

I have taken your advice on the 12F675 and ordered 5 to get started.

I read another follow up on this topic by mister_e and thank you very much, I had this problem for ages and wondered what was happening.

Will be greatful for any further suggestions.

Andy

Melanie
- 25th October 2004, 12:39
If you can remember your friends name, the Date of Purchase and the original point of purchase (ie MeLabs or Distributor), you can probably get them to look up the original transaction. As long as you have the original disk, I am sure you will be able to resolve an upgrade.

andyf
- 25th October 2004, 12:56
You get back quickly don't you. Thanks

Its likely i have no chance to find the details as I am not even at home where it would be, so I think the only option is to skip the upgrade idea and find another way.

I do understand the prinicple of programming the chips so could get by using the epic and some delphi code just have to find an example.

Do you know of a project using the 12F675 that will do what I am trying?

Are you the Mel in Melabs?

Andy

Dwayne
- 25th October 2004, 15:09
Hello Andy,

Andy>>Anyone fancy helping me with the project, I am sure for some this is like very easy, for me its a nightmare and I really would welcome some help.<<

Andy, if you go to compilespot.com, you can use the latest version of PBP. You are limited to 900 bytes, but with 900 bytes, that is PLENTY for your project...

If you are receiving that ASCII string via Serial... its even easier...

Use your Serial in command and set the "check str" to your SERIN as your "ASCII" string.

something like this...

Var="N";
Loop:
SERIN portx,N2400,[“ASCII”],Var,
if Var<>"N" Gosub turnonroutine.
goto Loop

turnonroutine:
Var="N"
PortX=1 'turn on that light
pause 1000 'pause 1 second
Portx=0 'turn if off
return


SERIN2 has a timer too, that could be very useful. I do not know what you will receive after the ASCII string... Maybe nothing? If so, you can still use the SERIN, and load up a array to check for your ASCII sequence.

Dwayne

andyf
- 25th October 2004, 15:40
Thanks Dwayne,

Thats spot on.

can I contact you directly?

Andy

Dwayne
- 25th October 2004, 21:34
Hello Andy,


Andy>>Thats spot on.

can I contact you directly?<<


Yes Andy, you may contact me directly. but always remember, there are *many* eyes on this board, and sometimes they may have a better way to accomplish things. There are programmers from all walks of life here.

Dwayne

Melanie
- 26th October 2004, 12:16
> You get back quickly don't you.

Only if you happen to hit it at the right time!

> Are you the Mel in Melabs?

No... I'm Melanie (high heels, slinky stockings and I give Microchip PICs a hard time). The other crowd is Micro Engineering Labs (as per the sticker on your Compiler disks), they also give PICs a hard time, but I can't vouch for their attire.

andyf
- 26th October 2004, 12:32
Do you use yahoo messenger or even the dangerious msn?

Andy



> You get back quickly don't you.

Only if you happen to hit it at the right time!

> Are you the Mel in Melabs?

No... I'm Melanie (high heels, slinky stockings and I give PICs a hard time). The other crowd is Micro Engineering Labs (as per the sticker on your Compiler disks), they also give PICs a hard time, but I can't vouch for their attire.





Report this post to a moderator | IP: Logged

- 26th October 2004 12:16

Melanie
- 26th October 2004, 13:10
No. All the Messanger type applications (icluding things like ICQ, cUcMe, IRC, etc) leave gaping great security holes in your computer networks.

The word Microchip has been inserted in to my previous post as embarassingly it could have been read with an unintential double meaning.

andyf
- 26th October 2004, 15:28
Anyway, I am still trying to do this project.

The chips are here now, I got ten to connect at once.

I have a good example from above but its still a long way really from what I am trying to do eventually.

As Dwayne suggested I can use this code but also assume I need to setup the ports as mister_e suggested above:


Var="N";
Loop:
SERIN portx,N2400,[“ASCII”],Var,
if Var<>"N" Gosub turnonroutine.
goto Loop

turnonroutine:
Var="N"
PortX=1 'turn on that light
pause 1000 'pause 1 second
Portx=0 'turn if off
return


So looking at this example I have an serial ascii string being watched for by the pic and when the pic sees the N the code goes to the turnonroutine sub routine for 1 second.

Is it correct to say then, if I serially send the alphabet in uppercase A-Z I can switch the light on for a longerstring of letters say MNO, so the light comes on only when all three characters have been sent and in the right order.

NMO OMN etc should not gosub to turnonroutine MNO should.


So if thats what I want to do, will this code be ok:

Var="MNO";
Loop:
SERIN portx,N2400,[“ASCII”],Var,
if Var<>"MNO" Gosub turnonroutine.
goto Loop

turnonroutine:
Var="N" Also why do I need this 'N' here?
PortX=1 'turn on that light
pause 1000 'pause 1 second
Portx=0 'turn if off
return


Not sure how many output bits are left after connecting the PIC to a serial port, I also eventually want to send the pic another code to see if the PIC is responding so bi-directional serial will be used. If that makes sence.

would be great to have this ability:



Send the PIC serially "MNx" where x is the port to turn on.
The PIC turns on port x for 1 second then returns to monitoring the serial data.


Send the PIC serially "MNi".
The PIC sees that code then transmits back "I am here",
then returns to monitoring the serial data.

so from what I have seen already with an 8pin PIC will this be possible?


5V
GND
Serin
serout

port1 - lamp 1
port2 - lamp 2
port3 - lamp 3
port4 - lamp 4


Hope I am not asking too much, I just dont want to do it wrong or re-invent the wheel.

Andy

Melanie
- 26th October 2004, 17:21
Just as an aside, have you seen this thread as a PC serial to PIC demo that plays with LED's...

http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=573

Dwayne
- 26th October 2004, 17:36
Hello Andy,


Andy>>So looking at this example I have an serial ascii string being watched for by the pic and when the pic sees the N the code goes to the turnonroutine sub routine for 1 second.<

Lets look a little closer, to make *sure* you understand the statement ok?

SERIN portx,N2400,[“ASCII”],Var,

This statement says the following. The Chip will be in receive mode until it receives some kind of ASCII charactors. In this case (above) the Var will recieve the Charactor following the Ascii string "ASCII"

if your transmitter transmits "ASCII5" Var will have the value "5" in it.

====================================

Another example...

SERIN portx,N2400,[“Hello”],Var

Var will recieve the next charactor after "Hello".


If your transmitter transmits "Hellow", Var will have the value of "w" in it.


(look closely at this next example and notice capitalization ok?)

if your transmitter transmits "hellow" Var will never have a value in it, and your SERIN will continue to receive data until it sees the string "Hello".

===================================

Andy >>Is it correct to say then, if I serially send the alphabet in uppercase A-Z I can switch the light on for a longerstring of letters say MNO, so the light comes on only when all three characters have been sent and in the right order.<<

Yes Andy that is correct.

Andy>>NMO OMN etc should not gosub to turnonroutine MNO should.<<

That is correct. It is also CASE sensitive! so MNO is NOT equal to mno.


So if thats what I want to do, will this code be ok:


Andy >>
Var="MNO";
Loop:
SERIN portx,N2400,[“ASCII”],Var,
if Var<>"MNO" Gosub turnonroutine.
goto Loop
<<

Well, you are very close... Var will NOT have MNO in it. Look at my example above where I gave "hellow" and "hello5"

Lets rewrite it a little ok??

Lets let the transmitter send "MNOY"

Loop:
Var="N";
SERIN portx,N2400,[“ASCII”],Var,
if Var=="Y" Gosub turnonroutine. 'Var Y=yes! go to subroutine!
goto Loop


Andy>>
turnonroutine:
'Var="N" Also why do I need this 'N' here?
PortX=1 'turn on that light
pause 1000 'pause 1 second
Portx=0 'turn if off
return
<<

Ok, I switched the Var=n to the main part instead...You want to make DOUBLEY sure the Var is not ALWAYS equal to "Y"!
also, you may want to see that light blink don't you??? if so, you need a pause "someplace" that is long enough to see the light in the off position. So you can add a "Pause 100" after you turn off the port.

Andy>>Not sure how many output bits are left after connecting the PIC to a serial port, I also eventually want to send the pic another code to see if the PIC is responding so bi-directional serial will be used. If that makes sence.<<

Andy with only 1 pin, you can control bunches of PICS. Remember the SERIN command? it will only work if a certain sequence of data is received.

Lets connect up 10 PICS (receiving PICS) on 1 PIC that is the transmitter ok?

SEROUT Pinx,N2400,"Chip1Y"
SEROUT Pinx,N2400,"Chip2Y"
SEROUT Pinx,N2400,"Chip3Y"

See how this works?? if the transmitter sends "Chip2Y", the other recievers will ignore the command...Why? because the SERIN is NOT "Chip2".

Andy>>would be great to have this ability:<<

You have it now... <g>


Andy>>Send the PIC serially "MNx" where x is the port to turn on.
The PIC turns on port x for 1 second then returns to monitoring the serial data.<<

I just showed you how to do it above! If you need some more help, just ask!


Andy >>Send the PIC serially "MNi".
The PIC sees that code then transmits back "I am here",
then returns to monitoring the serial data.<<

You have already been shown!... just ask!

Dwayne

andyf
- 27th October 2004, 08:52
Ok, to recap and hopefully stop pestering you guys this is what I assume is correct:


Loop:
SERIN portx,N2400,[“Chip1”],Var,

Monitor the serial port "X - TBA" until we see chip1, if found transfere the
following character into the var.

if Var= "A" Gosub turnonroutine_A
If the character after "Chip1" is "A" then goto the subroutine for A

if Var= "B" Gosub turnonroutine_B
If the character after "Chip1" is "B" then goto the subroutine for B


Var="0"
clear the var so it cannot have any further effect
goto Loop




turnonroutine_A:
Var="0"
clear the var so it cannot have any further effect

Port1=1 'turn on
pause 500 ' 1/2 second pause
Port1=0 'turn off
pause 500 ' 1/2 second pause
return



turnonroutine_B:
Var="0"
clear the var so it cannot have any further effect

Port2=1 'turn on
pause 500 ' 1/2 second pause
Port2=0 'turn off
pause 500 ' 1/2 second pause
return






One more thing confuses me with this:

SERIN portx,N2400,[“Chip1”],Var,

Will Var always only be one character in length?

So if my string sent was say chip1AZ would var just have the A and ignore the Z

mister_e
- 27th October 2004, 13:20
"SERIN portx,N2400,[“Chip1”],Var,

Will Var always only be one character in length?

So if my string sent was say chip1AZ would var just have the A and ignore the Z"

IMO without testing it, it depend if your VAR is a WORD or BYTE. If is a BYTE only A will be stored in. WORD size AZ will be stored. IF you want to receive more than one character i suggest you.

SERIN portx,N2400,[“Chip1”],Var1,Var2,Var3....

or you can use this also:

SERIN portx,N2400,[“Chip1”]
n=0
While Var !="z"
SERIN portx,N2400,ToBeStore
DataReceive[n]=ToBeStore
n=n+1
wend

this will allow you to store everything you want (depending of the PIC memory space) in a same variable DataReceive.

Dwayne
- 27th October 2004, 15:32
Hello Andy,

andy>>Ok, to recap and hopefully stop pestering you guys this is what I assume is correct:<<


Hey, keep on pestering us...This is what fun is all about. learning, helping, communicating, and enjoying.


Yes, you are correct. Now, if you want to control a bunch of chips, the same principal applies... for example

Transmitter chip:

Main:
.......
Gosub Loop:
goto Main

Loop:
SEROUT pinx,2400,"Chip3","Y"
if (pinRx <>1 goto Loop 'this is the pin to confirm received.

Serout Pinx,2400,"Hello World! this is Chip3"

Loop2:
Serout Pinx2400, Chip5,"Y"
If pinRx<>1 goto Loop2 'this is the pin to confirm received

Serout Pinx2400, "Howdy! my chip 5 is working\"
Return


Your receiver 3 is as follows:

Loop1:
Serin Pinx,2400,Chip3,Var
If Var <>"Y" then Loop1
PinRx=1 'send a high to the transmitter to tell it to send data fAST!

while val<>"\"
Serin Pinx,2400,val
LCDout Val
Wend
PinRx=0 ' don't keep that pin on! other receivers may need it



Your other receivers are exactly the same...Just change teh second line down from

Serin Pinx,2400,Chip3,Var

to

Serin Pinx,2400,Chip5,Var (for receiver 5)


Granted I did all of this in Psuedo code. But if you put the correct punctuation in it, it should come close to running. like putting the "N" before the 2400 to make it N2400, or whatever you like.

I am uploading a picture for you....don't mind my professional drawing...The chips are how mine look after a weeks worth of use <g>.

Dwayne

andyf
- 27th October 2004, 16:42
Hi Steve and Dwayne,

I only want the one character so this should be spot on
SERIN portx,N2400,[“Chip1”],Var

Melanies example code to connect to the PC looks a good start to impove the code and I will be connecting the pics to the pc eventually.

Kind of getting the idea now till you changed to using while/wend but can still kind of follow it.

Nice drawing, its exactly how my vision of connected pics would look, well similar.

Got a new problem stairing me in the face, the Epic programmer has 18 pins in the socket, and the 12f675 has just 8, I know its possible to do in curcuit programming but how is another thing.

mister_e
- 27th October 2004, 17:15
Hi andyf,


here's a few tips
http://microengineeringlabs.com/support/icsp.htm

so now look in datasheet for VSS,MCLR, PGD,PGD. connect it to the according pins on your programmer. and that's is. Once it's programmed, remove at least only MCLR pin or the whole ICSP adapter, if you have it, to make your apps work .

Dwayne
- 27th October 2004, 17:27
Hello Andy,

Andy>>Got a new problem stairing me in the face, the Epic programmer has 18 pins in the socket, and the 12f675 has just 8, I know its possible to do in curcuit programming but how is another thing.<<

well, I have great news for you...

If i remember correctly... just put your "Pin 1" of yoru 8 pin chip where "Pin 1" of your 18 pin chip would go... and it should program quite nicely...(If I remember correctly)... but check the Documentation, and see if both your 18 pin chip and 8 pin chip use the same pins for programming. I could be wrong on this (Its been a while, but maybe someone else could verify this. Most all the 18 pins have close to the same PortA set up. And the Port A setup is like the 8 pin Port A. Thus your programmer should work for 8 pins as well as 18 pins. Since I am at work, I cannot verify this, and I don't want to give you incorrect info...

Dwayne

mister_e
- 27th October 2004, 17:37
Nope,


18pins side 8 pins side
VSS 5 8
MCLR 4 4
PGC 12 6
PGD 13 7


but if you're using ICSP connector of EPIC see the above link... but i don't know if ICSP is available for all PIC on EPIC... as i expect it's supposed to.

Dwayne
- 27th October 2004, 18:04
Hello Steve,

Steve>>but if you're using ICSP connector of EPIC see the above link... but i don't know if ICSP is available for all PIC on EPIC... as i expect it's supposed to.<<

Thanks Steve!!! Thanks for verifying for me, and showing that my idea was wrong. I didn't have anything with me to check it out, because I use a ZIF socket to program my 8 and 18 pin sockets. I just stick them in and presto <g>.

Excellet point... just take a few wires and attach them like you said and presto.. You have a 8 pin programmer.

Dwayne

mister_e
- 27th October 2004, 18:11
I use Picstart to program my PIC in ICSP. I never use EPIC or other. What i do is to use DIP socket and solder those programming wires we need. at the other end of this "home made" adapter i put male header to fit in proto-board. That's cheap and work really well. I did for every different model. So it's quite simple to use them after.

One other thing you must be consider... be careful of the load on PGC,PGD pins. Programmer is not able to drive/sink lot of current. Even i use these pins for push button entry with pull down resistor. Usually more than 20K is working fine. In some other apps, i did a special ICSP connector that switch PGC,PGD pin from on board parts to programmer when ICSP connector is applied. That is usefull on these 8 pins PIC where all i/o are usefull. In case you use 8 pins, don't forget you can not use MCLR pin as an i/o, in case, no update will be available instead if you remove it from circuit.