View previous topic :: View next topic |
Author |
Message |
starfire151
Joined: 01 Apr 2007 Posts: 195
|
async/serial interface with 12f675 at 32.768KHz? |
Posted: Mon Dec 31, 2007 5:58 pm |
|
|
I tried a basic circuit with a PIC12F675 running with an external 32.768KHz crystal (to maximize battery life) and an Intersil ICL3232 (MAX232 clone which runs at voltages from 3.0VDC to 5.5VDC, has a quiescent current of 1uA, and uses 0.1uF external caps) to see if I could get any kind of serial interface working to the PIC. The system used a 3.0VDC power supply (two AA celss, which measured 3.2VDC with a meter).
I selected the NOMCLR fuse option and selected A3 as the serial input and A2 as the serial output pins.
I tried 300 baud and 110 baud. 300 baud gave invalid characters to a HyperTerminal session and 110 baud gave no response at all.
What is the lowest practical oscillator/crystal rate anyone has run a micro and have a serial interface of some type? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 31, 2007 6:12 pm |
|
|
Test it with the internal oscillator, running at 4 MHz. Try it at 9600 baud.
See if it works. This will test if your hardware is wired correctly.
This post has an example of a test program to do this:
http://www.ccsinfo.com/forum/viewtopic.php?t=33084&start=19
Change the pins to match your hardware. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
9600 baud at 4MHz is good |
Posted: Mon Dec 31, 2007 6:53 pm |
|
|
I tried the internal oscillator (#fuses INTRC) with the circuit pins as described previously (A3 is recv, A2 is xmit) and it works fine.
I had bi-directional communications. I could print an init message from the PIC to the HyperTerminal and I could receive commands to toggle a pin into the PIC. I also echoed the input commands back to the HyperTerminal correctly.
4MHz seems to work correctly... |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: async/serial interface with 12f675 at 32.768KHz? |
Posted: Tue Jan 01, 2008 3:16 pm |
|
|
starfire151 wrote: | I tried a basic circuit with a PIC12F675 running with an external 32.768KHz crystal (to maximize battery life) and an Intersil ICL3232 (MAX232 clone which runs at voltages from 3.0VDC to 5.5VDC, has a quiescent current of 1uA, and uses 0.1uF external caps) to see if I could get any kind of serial interface working to the PIC. The system used a 3.0VDC power supply (two AA celss, which measured 3.2VDC with a meter).
I selected the NOMCLR fuse option and selected A3 as the serial input and A2 as the serial output pins.
I tried 300 baud and 110 baud. 300 baud gave invalid characters to a HyperTerminal session and 110 baud gave no response at all.
What is the lowest practical oscillator/crystal rate anyone has run a micro and have a serial interface of some type? |
Baud rate should be a factor of the crystal speed. I would suggest using a baud of 9600 and a crystal of 38400. You should see almost no change in the power draw but 9600 is much more likely to work with most serial ports. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Tue Jan 01, 2008 5:04 pm |
|
|
Quote: | Baud rate should be a factor of the crystal speed. I would suggest using a baud of 9600 and a crystal of 38400. You should see almost no change in the power draw but 9600 is much more likely to work with most serial ports. |
I thought the serial port data input was based on the baud clock times 16... Is this not correct? The theory was to oversample the input and find the middle of the bit period based on eight clocks from the high-to-low transition of the start bit.
If this is true, a baud rate of 9600 would need a minimum of 9600 * 16 = 153.6 KHz for the crystal? |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Thu Jan 03, 2008 12:14 am |
|
|
Your right I was thinking of another PIC series. |
|
|
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Thu Jan 03, 2008 8:42 am |
|
|
Put that signal on a scope! See where it goes south... |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Sat Jan 05, 2008 2:05 pm |
|
|
OK... it was a good suggestion to scope the xmit and recv lines. I did. What I saw going in was exactly correct. I sent an 'r' character and saw the correct bit pattern. I did this at 300 baud, no parity, 8 data, 1 stop, no handshake. A little more checking with variations of the program and it appears the getc() function doesn't work at this low a baud rate with this low a crystal frequency. Oddly enough, the printf() function works fine. I trapped the initial start-up printf() message and it wrote correctly to the HyperTerminal session. While kbhit() seems to work, when you try to get the character (with a ch = getc() function call), it locks up the system. I commented out the call to the getc() and added a call to an output statement (printf() with 11 characters being output), and it printed correctly. Again scoping the output line, the correct bit pattern was seen and also showed up on the HyperTerminal session. It seems this configuration is good at outputting data but not at reading it in... ?? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat Jan 05, 2008 9:28 pm |
|
|
For us to reproduce your problem we ask the standard questions:
- What is your compiler version?
- Post a short but complete example program (max. 20 lines including #fuses statements, etc.). |
|
|
coast
Joined: 03 Jan 2008 Posts: 6 Location: WALDERSLADE, KENT,UK
|
rs too three too |
Posted: Sun Jan 06, 2008 8:42 am |
|
|
You are slighty missing the point (maybe) cos you also need to think about the stabilty of yr oscillator. You can get to the lower baud rates using a 1 meg resonator with built-in caps (3 pin device) but the optimum is 2MHz simply cos this will get you acceptable stability/ jitter performance....with a 2MHz resonator you can get wholely reliable 9600 baud comms with a 16f870 for example. ! or 2 megs clock is also OK for ickle chips like 12f672 if you stick to the lower baud rates (cos you will need to use bit bashed routines). Forget about using a 37K watch crystal....it won't work...don't try....Bhodi Satva spent 7 years looking at a wall but you probably don't have that level of patience.
PS don't even think about using anything other than a crystal for CAN automotive stuff...cos you won't meet temperature specs otherwise. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Sun Jan 06, 2008 11:16 am |
|
|
I'm using version 3.249 of the compiler.
Here's a small listing:
Code: | #include <12F675.h>
#device adc=8
#fuses NOWDT, LP, NOPROTECT, NOMCLR, PUT, NOBROWNOUT
#use delay(clock=32768)
#use rs232(baud=300, parity=N, xmit=PIN_A2, rcv=PIN_A3, bits=8)
#define HEARTBEAT PIN_A0 // Out: heartbeat toggle
void main()
{
char ch;
setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
set_tris_a(0x08); // a0, a1, and a2 : outs; a3 : in
port_a_pullups(0x07); // pullups on a0 through a2 (no pullup on a3)
set_rtcc(0);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_8 | RTCC_8_BIT);
output_high(HEARTBEAT);
delay_ms(500);
printf("12F675 init OK\r\n");
delay_ms(500);
ch = 'x'; // default char
while(TRUE)
{
if(kbhit())
{
// ch = getc(); // get char
output_toggle(HEARTBEAT);
printf("%c ", ch); // print char
}
}
}
|
Note this should work as stated because the getc() function is commented out. You will get an 'x' for every key you press. Uncomment the getc() and the system dies... at least my system dies
The hardware is a PIC12F675 with a 32.768KHz crystal (DigiKey 300-1001-ND), a pair of 20pF ceramic caps from each end of the crystal to ground, an Intersil ICL3232 RS232 interface chip with the associated 0.1uF caps, and a three-wire interface to the PC running HyperTerminal at 300 baud, no parity, 8 data, 1 stop, no handshake. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 06, 2008 2:35 pm |
|
|
I tested your program with vs. 4.064 and it fails in the same way
you describe. I then decreased the baud rate to 110 baud. Then
it started working. Though, you have to be careful to allow a little
time between the characters as you type them.
I didn't go through the listing and add up instruction times, but the
implication is that with an 8192 Hz instruction clock, it takes too long
for the CCS software UART library code to handle an incoming
character at 300 baud. |
|
|
starfire151
Joined: 01 Apr 2007 Posts: 195
|
|
Posted: Sun Jan 06, 2008 7:48 pm |
|
|
Thanks for checking this. I couldn't get it to work at 110 baud, either. I suspected the library call was a little too slow for a very slow clock rate, as you've said.
I just wanted to see what the lowest practical oscillator/crystal frequency anyone had used to maintain a good serial interface. I'm trying to maximize battery life by decreasing the operational frequency but still maintain a minimal bi-directional communications method.
I suppose I could detect the falling edge of the start bit and count clock cycles to check bits in the middle of the bit periods.
Thanks again. |
|
|
|