When configuring MCLR'/VPP as GP3 for input on the 12F683, do you program it afterwards via the same protocol - i.e.- does the programming function of the MCLR'/VPP pin change, or will I still be able to program via ICSP as normal?
Printable View
When configuring MCLR'/VPP as GP3 for input on the 12F683, do you program it afterwards via the same protocol - i.e.- does the programming function of the MCLR'/VPP pin change, or will I still be able to program via ICSP as normal?
You can set it up for an input from the beginning of the program then still use it later for programming. Just make sure your circuit will still allow the Vpp signal to control it during programming otherwise it will boop at you and report an error.
And make sure you circuit will handle the programming voltage.
I like to use some method of isolation when programming. The simplest is a two pin header with a jumper clip.
Makes sense, thanks guys - I had planned on input circuit isolation at the pin, but wasn't sure if there was some other issue that I'd run into during subsequent programming...
Thanks again, and happy new year all!
Hi, new to this forum and to PIC's in general. I fly RC and have used a 12F683 to act as failsafe system for 3 servos.
I've tried the pulsout command but the output just goes HI?? (I have scope to check).
Here is the code:
pos var byte ' Define our storage location for the servo position information.
servo var byte ' Define our storage location for the servo number to move.
cont var byte ' Define a variable to hold the count.
' 4 mhz clock internal
' 500 = 1 ms
' 1000 = 2 ms
' 1250 = 2.5 ms
pos = 1250
start:
for cont = 0 to 50
pulsout portb.4,pos ' Send servo# ? to position ?.
pause 20 ' Wait 20 ms.
next cont ' Next pulse.
goto start ' Return to get more serial input.
Can anyone help??
Try changing pos to a WORD size var and see if that helps
Thanks! it worked on the 16F84A chip.
I'm still having difficulty with the 12F683 though. The pulsout doesn't seem to work. I wonder if the chip supports that command?
I've also tried running the servo by setting the pin high and low timing the high between 1 to 2 ms and the low to 20ms. It works, but it won't accept a decimal number:mad:.
at 4 mHz, I need to pause for between .5ms and 2.5ms but it only accepts 1 and 2 !!!
suggestions??
John.
p.s., here's the code:
posit var word
cont var word
cont2 var word
Q var word
let posit = 3/2
Let Q = 25
start:
for cont = 1 to 50
high 0
pause posit
low 0
pause 20
next cont
goto start
It doesn't show in your code so I will assume that the device has not been configured to what you want to do with it since it has other features.
Start by setting the oscillator then the ports with the TRISIO command, found on page 35 of the data sheet, shut OFF the comparators and the A/D feature:
Then use the PAUSES command instead of PAUSE for a better resolution of the timming you need:Code:OSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
PAUSE 1 gives you 1ms where PAUSES 1000 will do the same but now you can get your 1.5ms with PAUSES 1500.
Didn't know how to edit last post so:
Use GPIO.# instead of PORTB.# per pg. 35 of data sheet.
That should be PAUSEUS not PAUSES.
PAUSEUS will pause microseconds, not milliseconds.
If you let PBP devide 3 by 2 then you will always get 1 as an answer.
So if you want to pause 1.5 milliseconds use PAUSEUS 1500 instead.
happy new year
Thanks LinkMtech and eggman (sounds like a TV show in the making!). I'll try your comments today.
Happy new year to both of you.
John.
Thanks gents, both option worked like a charm.
Cheers!:D
OK, anthor problem...
I'm trying to run an RC servo from a PIC12F683. I'm using pin 0 as output and pin 1 as input (from receiver)
As long as there is a signal from pin 1, the PULSOUT will output the PULSIN value. When no signal is present (PULSIN=0) then PULSOUT should go to a failsafe value.
Situation: When the signal is present, the PULSOUT sends the PULSIN value, but when PULSIN = 0, the PULSOUT does send the proper value, but in 1/2 second intervals (it pulses the value about every 0.5 sec). I can't figure out why!!!
here's the code:
oSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
cont var word
failsafe var word
posoutput var word
posinput var word
usefailsafe var byte
pausetime var word
low gpio.0
low gpio.1
low gpio.2
low gpio.3
failsafe=80
pausetime=10
START:
;pulsout portb.4, failsafe
;pause 50
;goto start
GETSIGNAL:
pulsin gpio.1,1,posoutput
if posoutput=0 then goto runfailsafe
goto runnormal
runfailsafe:
pulsout gpio.0, failsafe
pause pausetime
goto getsignal
runnormal:
pulsout gpio.0, posoutput
pause pausetime
goto getsignal
I have one more...
I want to write the PULSIN value to the memory on the 12F683 (and have it stored even when the power is off) and recall it in the event there is no PULSIN signal.
What are the proper commands to do this?
(I assume write and read)
I.e.
WRITE 5, failsafe
READ 5, failsafe
...but first I have to get the servo thing working!!
This may help with your data storage.
The below code is for a counter, sort of like an odometer. It saves the value to EEPROM at each hit of a switch. When the device is turned on the EEPROM is read and the values placed back into a variable for continued use. Also has the ability to reset the stored values back to zero at start up.
Pick through it and see if it helps.
Code:'* Notes :16F877A
'* SAVE TO EEPROM
'****************************************************************
'_config _HS_OSC & _WDT_ON & _LVP_OFF & _CP_OFF &_BODEN_OFF
DEFINE OSC 20
DEFINE LCD_DREG PORTB
define LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50
TRISA = %00000000
ADCON1=14
Asm
ERRORLEVEL -306
Endasm
include "modedefs.bas"
'TOTAL VARS
O VAR BYTE 'ONES
T VAR BYTE 'TENS
H VAR BYTE 'HUNDREDS
TH VAR BYTE 'THOUSANDS
TTH VAR BYTE 'TEN THOUSANDS
HTH VAR BYTE 'HUNDRED THOUSANDS
M VAR BYTE 'MILLIONS
OD VAR BYTE 'ONES
TD VAR BYTE 'TENS
HD VAR BYTE 'HUNDREDS
THD VAR BYTE 'THOUSANDS
TTHD VAR BYTE 'TEN THOUSANDS
HTHD VAR BYTE 'HUNDRED THOUSANDS
MD VAR BYTE 'MILLIONS
'TOTAL LOGS
O_LOG VAR BYTE 'ONES
T_LOG VAR BYTE 'TENS
H_LOG VAR BYTE 'HUNDREDS
TH_LOG VAR BYTE 'THOUSANDS
TTH_LOG VAR BYTE 'TEN THOUSANDS
HTH_LOG VAR BYTE 'HUNDRED THOUSANDS
M_LOG VAR BYTE 'MILLIONS
'READ LOGS
READ O_LOG, OD
READ T_LOG, TD
READ H_LOG, HD
READ TH_LOG, THD
READ TTH_LOG, TTHD
READ HTH_LOG, HTHD
READ M_LOG, MD
NUM VAR BYTE
NUM = 0
pause 1000
CHECK:
IF PORTE.2 = 1 THEN GOSUB CL_LOG 'FOR RESET AT START UP
IF PORTE.2 = 0 THEN START
GOTO CHECK
START:
HIGH PORTD.2 'LED
PAUSE 5
IF PORTD.3 = 1 THEN GOSUB C_P_T 'SWITCH FOR PARTS
LOW PORTD.2
PAUSE 5
GOTO START
C_P_T:
LCDOUT $FE,1,"C TEST"
LCDOUT $FE,$C0,DEC MD,DEC HTHD,DEC TTHD,DEC THD,DEC HD,DEC TD,DEC OD
O = O + 1
IF O = 10 THEN
O = 1
T = T + 1
IF T = 10 THEN
T = 0
H = H + 1
IF H = 10 THEN
H = 0
TH = TH + 1
IF TH = 10 THEN
TH = 0
TTH = TTH + 1
IF TTH = 10 THEN
TTH = 0
HTH = HTH +1
IF HTH = 10 THEN
HTH = 0
M = M +1
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
WRITE O_LOG, O
WRITE T_LOG, T
WRITE H_LOG, H
WRITE TH_LOG, TH
WRITE TTH_LOG, TTH
WRITE HTH_LOG, HTH
WRITE M_LOG, M
READ O_LOG, OD
READ T_LOG, TD
READ H_LOG, HD
READ TH_LOG, THD
READ TTH_LOG, TTHD
READ HTH_LOG, HTHD
READ M_LOG, MD
RETURN
CL_LOG:
HIGH PORTD.2
PAUSE 100
LOW PORTD.2
PAUSE 100
O = $0
T = $0
H = $0
TH = $0
TTH = $0
HTH = $0
M = $0
WRITE O_LOG, O
READ O_LOG, OD
WRITE T_LOG, T
READ T_LOG, TD
WRITE H_LOG, H
READ H_LOG, HD
WRITE TH_LOG, TH
READ TH_LOG, THD
WRITE TTH_LOG, TTH
READ TTH_LOG, TTHD
WRITE HTH_LOG, HTH
READ HTH_LOG, HTHD
WRITE M_LOG, M
READ M_LOG, MD
RETURN
END
I found that PULSIN will time out while you're waiting for something to happen then was clued in on WHILE:WEND.
So try this command set with something like:
It comes in handy for something like this.Code:WHILE GPIO.1 = 0 ' Repeat this loop while there is no signal
pulsout gpio.0, failsafe
pause pausetime
WEND
Thanks LinkMTech and Mackrackit:
Both worked. FYI, I fly RC planes and have recently gained interest in the PIC stuff, mostly with the 12F683 due to its size. I'm learning this stuff...slowly (but wow, has it got potential!).
I have a couple more questions hopefully you can help me with.
1. having some issues simply running LED's on ports other than gpio.0 and 1. I'm not sure if I need to assign them, change them??? When trying, I see they have a faint glow???
2. When using GPIO.4 and an input to store a pulsin value, the program works, but if I use GPIO.3 it doesn't. I can't figure that one out.
Thanks again gents.
John.
I crashed my RC aircraft using the PULSOUT command.
PULSOUT is a 'toggle'. Whatever state the pin was in, it will flip for the duration specified in the PULSOUT command. That is bad news if your servo pin gets clobbered and you were expecting it to be low when you called the PULSOUT routine.
To be safe, you MUST predefine the pin state before calling PULSOUT.
e.g.
LOW ServoPin
PULSOUT ServoPin, 500
will work every time.
HTH
Brian
Whoops, sorry about that!
here's the code:
oSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
input gpio.4
inpulse VAR Word
memory var word
low gpio.4
low gpio.3
start:
SEROUT 0, 2, [12]
start2:
PULSIN 1, 1, inpulse
if inpulse<50 then
read 5, memory
serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
goto start2
else
endif
if gpio.4=1 then
write 5, inpulse
serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
high gpio.3
low gpio.4
else
low gpio.3
endif
SEROUT 0, 2, [17,22,#inpulse*10]
PAUSE 20
GOTO start
END
OSCCON = %01100000 ' Ocs set to 4 MHz
TRISIO = %00000000 ' Set all ports to outputs, in this example
CMCON0 = 7 ' Analog comparators off
ANSEL = 0 ' Analog select set to digital, pg 69 data
ADCON0 = 0 ' A/D turned OFF, pg 68 of data
input gpio.4 '<font color=red> make input</font color>
inpulse VAR Word
memory var word
low gpio.4 <font color = red> ' Now you make it an output</font color>
low gpio.3
start:
SEROUT 0, 2, [12]
start2:
PULSIN 1, 1, inpulse
if inpulse<50 then
read 5, memory
serout 0,2,[12,17, "Activating",13,"Failsafe :", #memory*10]
goto start2
else
endif
if gpio.4=1 then '<font color=red> still an output, are you wanting an input?</font color>
write 5, inpulse
serout 0,2,[12,17,"Failsafe",13,"Stored :", #inpulse*10]
high gpio.3
low gpio.4 '<font color=red> is and should be an output</font color>
else
low gpio.3
endif
SEROUT 0, 2, [17,22,#inpulse*10]
PAUSE 20
GOTO start
END
Thanks Joe,
I didn't catch that, I'll make changes and see if that fixes the input problem.
I still have the output issue though with GPIO.3, it doesn't want to run the LED.
Any thoughts?
John.
Not sure but I think that pin is input only.
I dunno John, I never use the High / Low convention, preferring to specify TRISIO AND GPIO instead because as I understand it , High/Low reads modify's and writes the whole port ( all the I/Os ) when you do.
Thanks guys,
I think I've got it working OK now...but by copy of the picbasic compiler (with microcode studio) only limits me to 31 code lines:mad:
As much as I like Microcode Studio...is there something out there a guy can use that is much cheaper than picbasic pro AND is downloadable from the NET?
John.
http://www.oshonsoft.com/pic.html
About US$70, Unlimited demo, FREE for 30 days.
http://www.mikroe.com/en/compilers/mikrobasic/pic/
US$149, FREE demo limit 2K code (with the PIC12F683, you fill the entire program memory with the demo).
Oops, left out my favorite (only for PIC18's though) - US$149, Demo limited to 256 bytes of RAM, no restrictions on code size:
http://www.sfcompiler.co.uk/swordfish/
I tried mikrostudio...I like the picbasic code better (maybe because I'm learning on that platform). I also have MPLAB that came with my pickit2...but it works on asm. I appears if I get the picbasic compiler that I could program in MPLAB using picbasic???
Is that right?
JOhn.
MPLAB and PBP work very well together. I normally use MPLAB over MCS.
http://www.melabs.com/support/mplab.htm
I was looking in to C compilers last year, and got some great feedback from a guy whose job requires him to be familiar with just about every pic compiler. (His feedback was offline, because he could not post his opinions public for the same reason he knows about all of the compilers. I am going to respect his anonymity.) Anyway, his advice regarding Mikroe and their compilers was to avoid them, for a variety of reasons. (Which mostly boiled down to "you get what you pay for.")
I own PBP, and find it a great compiler for people wanting to step up from Stamps. I mostly use Proton Basic (PDS), however, because it compiles much more compactly (about 20%) and runs faster. It's only $165, and even comes with a simulator that allows you to step through your code and debug much faster. The sim is limited to a couple chips and a couple development board models, but that allows you to test routines without messing with hardware. (I purchased the full sim so I can create just about any circuit I can think of--but that is not cheap.)
For the most part, you get what you pay for in compilers. Comparing PBP to PDS, they are very similar (they both used BS2 as a base), but PDS is more powerful. The same guy mentioned above said PDS "is as close to coding in asm as it gets for any pic compiler." The biggest difference is that PBP is a little more oriented (better oriented?) towards beginners because it has fewer features to trip you up. PDS has a larger command set, and built in interrupt context saving. The parser is better with PBP, so you can string together many math equations on one line with lots of parentheses to make it readable...but if you separate them out and use PDS, your code will be a LOT smaller.
Would you care to share the reasons why your guy said to avoid mikroE?
This is what he said that I can share: "mikroC has a good support of internal libraries but the binary code is not that optimized". Like I said, the rest boiled down to "you get what you pay for." If you want cheap, you get cheap... either minimal features, buggy or bloated code. Nobody makes a compiler that is bug-free, optimized, and feature-full.
And, more importantly for me, I use the Proteus PIC/Spice simulator for debugging my code, and the Mikro compilers put out a proprietary format (not a standardized format), so it is only useful for use with their own debugger.
You can always use PicBasic (instead of PicBasic Pro), which is a lot cheaper, and almost certainly bug-free... but it has minimal features and no optimization. There's also the free Pascal-like compiler, JAL: http://www.voti.nl/jal/
while cheaper is not always better, even if you pay a single full license for Hi-Tech C (more than 2K) but cover ALL PIC familly (from 10F to Dspic, PIC32), you won't have the peace of mind. Most of those I know of, have now moved on Microchip ones. OK they're still expensive, but they seems to be better with years than Hi-Tech (That's what i've heard and experimented myself awhile back).
However, the only single language that cover EVERY PIC familly and which is free is ASM. That's great, but a real pain to program in, and it's syntax change from a familly to another, more noticeable on DsPIC/PIC32. Good news is, the only person you will be abe to blame when a bug will appear one day or another is you.
Depending where you are located in the product food-chain, ASM is great or bad.
For every compiler on the market, we heard good and bad comments... same things goes for all device programmers, IDE, etc etc etc. What I hate is to learn 3,4,5,6,7...10 different compiler to do a single job.
Knowing your compiler is great, knowing your own limit is great, ASM cover everything, but you must know and admit your personal limit/time.
It's a full piece of crap to say that ASM is faster... it's really up to the pepper back of the keyboard.... hence why performance of each and eavery compiler differ for the same single task.
Time wasting... is this a real waste, or knowledge improvement... who knows? On the other side, who care of a developer knowledge if another do it WAY faster... once it's burned in a black pinned box, and do the job as per the customer requirement, no one will care of the tool you used.
Same bull**** happen with PC... C is better than Basic... euh NO SIR your $%!$%^#@ wrong C#... Delphi... Python....Java is better... crap crap crap... unfortunately, actual market is... faster is better... crap crap crap...
Wow, seems I opened up a can of worms there;)
I was looking over ASM earlier (from a beginners perspective) and learned how to convert binary to hex (amazingly simple...after a 3-finger scotch!)
Still, ASM, as you all have essentially indicated, is ... a pain.
I'm checking out PDS...and don't see if it supports pickit2 and a programmer (anyone know?).
I think i'll end up purchasing either PDS or PBP...both look great!
Thanks for all you're input!
John.
The PICKIT2 will load the generated hex, does not matter who or what created it.
Can of worms?
What did you expect, I like Fords, are they better :)
I agree with with Dave, that is why I suggested that you try them out and judge for yourself rather than relying on the opinion of third parties. I did indicate my favorite though - just like Dave did. :D