![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 | |
|
Hello all. This is my first post, althought I've been reading this forum quite a bit. Excellent stuff! Anyways, I hope there is someone out there that can help me with my little PIC-Chip. I'm a novice with PICs, but I have a good project which require RS232. I have managed to to it with a 16F627, but I need ADC on a small footsprint, so I went for the 12F675. After I rewrote the code to fit the 12F675, I just couldn't get it working. I was banging my head against the wall for weeks, but I just couldn't figure out why. My suspicion is that I overwrote the OSCCAL values. I'm not sure if I can read the location of that value, since the programmer I'm using (Velleman) is not that good. If I jump to that address, as part of the recommended calibrarion routine, the PIC hangs. I'm pretty sure it's lost, is this what you would expect from an overwritten OSCCAL value? 3F3F, I'm not even sure what that transelates to in Opcode. I've ordered a proper programmer, which should arrive next week BTW: Two good links to pages regarding OSCCAL: http://users.tpg.com.au/btkelly/pic/osccal_sync.html http://www.petesworld.demon.co.uk/ho...PIC/piccal.htm I'll post my code below for anyone to check. Sorry for the mess, couldn't get the table thing to work. I've written it as simple as possible, with no trixi parts. Is my code ok? Does it do what I want it to do? (Which is to output an ASCII letter every now and then )Quote:
Does anyone know the aproximate frequency-range for the internal oscilator? Oh, and the project I'm doing with this particular PIC is a circut that samples temperature and moisture, and sends it down RS232. I will actually use this on work. I'll post the whole project when it's done, if anyones interested. All replies are most welcome. And thanks again everyone for an excellent forum. | ||
| |
| | #2 |
|
Your code is too horrible to look at! ![]() Check the datasheet for the BCF and BSF instructions, you DON'T access individual pins in that crude fashion on a PIC, only on inferior antique processors!. You also use a loop to send 8 bits!. You should also check my tutorials, although for the 16F628 they only require very slight changes for the 12F675, and include nice reliable RS232 routines!. | |
| |
| | #3 |
|
Yeah, sorry for the bad code. I was using BCF and BSF, together with a incremental barrell function (To print the whole ASCII-table). but I thought this was easier to debug (at least for me ), because I think it is a timing error.(Thanks for the quick reply BTW - And I loop to send 10 bits :P )
Last edited by johankj; 30th January 2007 at 08:51 PM. | |
| |
| | #4 | |
| Quote:
The calibration value is in the last location and is read/written as any other location by the (hardware) programmer. The software can take care of it or you have to write the known value manually, after transferring the code. Second problem: you can't use the calibration routine when the last location contains 0x3F3F. You need a RETLW (0x34) instruction (with a random calibration value). 0x20 selects the center frequency for example. You may try some values or use a crystal (if you have enough I/O pins). EDIT: 0x20 = b100000 (only 6 bits are used in the OSCCAL register and they are left justified. Last edited by eng1; 30th January 2007 at 11:43 PM. | ||
| |
| | #5 |
|
h20=b100000=d32 I see.So I guess I could just move that into OSCCAL, and see if I get lucky. The data-sheet doesn't say, does anyone know how much a 1 inreases/decreases the frequency? I remember reading somewhere that it was tested to ~0.78% But does Microchip say anything about it. I just thought of something. I have a Fluke 110 multimeter, which can measure frequencies up to 50kHz = 20uS period. I'll just use it to measure the 104uS period, and then I'll see if it caribrated. I'll just modify the code to go 0101010101... Hopefully the fact that it's a square-wave matter. 4.230 Khz +-0.1% + 231.5 +-0.1% uS on min values (000000xx) 5.730 Khz +-0.1% = 174.5 +-0.1% uS On reset values (100000xx) 7.610 Khz +-0.1% = 131.4 +-0.1% uS On Max values (1111111xx) Well, I could detect a change, but not as detailed as I hoped. Those values are off. ![]() Neither of them worked, sadly. Well, time to hit the sack. I'll try again tomorrow, maybe lower the frequency or something. I'll guesse I'll be ordering a few more of these, and then learn from my mistake... | |
| |
| | #6 | |
| Quote:
I usually place a delay routine after the calibration... I don't remember if it's necessary, but I think that the oscillator takes some time to become stable. Last edited by eng1; 30th January 2007 at 11:48 PM. | ||
| |
| | #7 |
|
First, build RS232 softcode on a known good stable PIC set to same internal RC frequency as the 12F675. Once working good, copy over to 12F675. For all my 12F675 projects, I include a power-up configurator for the oscillator. If a push a button or just pull an i/o line high during power-up, PIC will go into config mode. I use a scope to monitor another i/o line which when calibrated should be a solid 4 MHZ wave. This was done because I had crap PIC programmers and had no choice but to reconfigure the PIC oscillator value after each flash. Basically, the current frequency is show on scope, and if you wish to adjust, just hold down or tap the button till desired frequency is met. Each button tap saves the oscillator into eeprom. What is not seen is that on power up the PIC automatically loads the oscillator value from eeprom and sends it to OSCCAL. Last edited by donniedj; 31st January 2007 at 03:42 AM. | |
| |
| | #8 |
|
hi, I bought a bunch of 12F629's a while ago, before i did any programming i read every chip and noted the oscal value for each chip. This saved me alot of hassle later on, i suggest you do the same. | |
| |
| | #9 | |||
| Quote:
My next question would be if there is any harm, or a minimum grace period in repeatedly writing to the OSCCAL register. I guesse not. Quote:
Quote:
I'm gonna write a small program that does what I said tonight, I'll post the results. | ||||
| |
| | #10 |
|
Success!!! I wrote a program that is a vertion of donnidj's idea, but simpler. It starts OSCCAL at zero on reset, then writes an 'A' on RS232. It then adds 'one' to the OSCCAL value, pauses, and returns to the loop. Here's what it looks like in the terminal, copied and pasted to Notepad to easier see where OSCCAL 'loops': ![]() Interestingly, the rs232 seems quite robust, syncing for OSCCAL values about 14 values apart. I went for the middle one, of course. Now where did I write down that OSCCAL value? ![]() Thanks everyone for suggestions and help. | |
| |
| | #11 |
|
I needed near perfect 1 microsecon instruction cycles because I was measuring high velocity projectiles in my chronograph. Now the RS232 is robust because it has a high tolerance, both the PIC and the PC. Alot of PC's and devices's rs232 clocks are far from being at center frequency of their baudrates. Get a good Digital scope and take a look at a sweep of baud rates transmitted out of your PC. You will wonder how two devices even communicate with the level or error in timing it produces. RS232 has gotten away with this large tolerance because the baud rates are multiples of each other as oppossed to being small increases next to each other like 9.6K, 9.7K, 9.8K... Please make this lesson's check out to "donniedj". Thank you Last edited by donniedj; 1st February 2007 at 02:38 AM. | |
| |
| | #12 | |
| Quote:
You inscribed it on the underside of the chip using a sharp pin. This is the first thing I do when I got the new chip.
__________________ L.Chung | ||
| |
| | #13 | |
| Quote:
It makes you realise that the 1% internal clock is easily accurate enough for RS232 at any speed the hardware supports. BTW, well done on finding an elegant and simple method to recalculate the OSCAL value. Mike. | ||
| |
| | #14 | |
| Quote:
Obviously for the timing question though it makes no difference at all. | ||
| |
| | #15 |
|
Here is Microchip's application note on how to auto-recalibrate the internal oscillator on PIC12F6XX chips in the event that it is lost. http://ww1.microchip.com/downloads/e...tes/00250a.pdf You can get the source code by searching the Microchip site for an250.zip. | |
| |
|
| Tags |
| softrs232, syncning |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| PCMCIA to RS232 for ICD2 clone | clockdoctor | Micro Controllers | 6 | 7th April 2008 11:10 PM |
| Cannot read 12F675 with ICSP | dprischak | Micro Controllers | 4 | 1st June 2006 03:37 AM |
| RS232 buffer | TDY | General Electronics Chat | 3 | 18th March 2005 09:36 PM |
| rs232 to rs232 data logger with 1meg buffer -help needed | ccaammaaccaazzii | Electronic Projects Design/Ideas/Reviews | 11 | 20th October 2004 10:43 PM |
| I²C and RS232 on the same PIC | l30 | Micro Controllers | 2 | 3rd July 2004 04:14 AM |