|
|
View previous topic :: View next topic |
Author |
Message |
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
pic 12F615 uart / clock issues, delay does not seem to work |
Posted: Thu Mar 10, 2011 7:04 pm |
|
|
Hello,
I'm working with a small cheap MCU and I was using the rs232, positive its software rs232 ? Anyway if i set the clock at something like 1M and make it blink a light for a second it blinks it very rapidly like 3 times a second, if i make it like 4M or 6M the light will blink slower, close to a second.
This leads me to belive the timing is off. All this matters because i'm using the uart and transmitting a char, all i get out is jibberish (0xFF).
Do you think its the chip or is the internal RC not good enough for reliable timing ? I dont think I have any crystals with me but I might try and find one.
I have tried several different settings for the clock and flags but this is what i ended up on
*note IOSC4 and IOSC8 cause the chip to do nothing !
Code: | #include <12F615.h>
#device adc=8
#fuses XC,INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,STOP=1)
#include "main.h"
char got = 'x';
int i;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
// TODO: USER CODE!!
while(1){
for(i = 0; i<10; i++)
{
delay_ms(1000);
output_high(PIN_A2);
delay_ms(1000);
output_low(PIN_A2);
putc(got);
}
output_high(PIN_A2);
delay_ms(5000);
output_low(PIN_A2);
delay_ms(5000);
i=0;
}
}
As always, thanks for your great product and unparalleled support ! |
_________________ Smart people know how stupid they are. |
|
|
vinniewryan
Joined: 29 Jul 2009 Posts: 154 Location: at work
|
|
Posted: Thu Mar 10, 2011 8:16 pm |
|
|
Quote: | #fuses XC,INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT |
I couldn't find XC as a valid fuse in the header file, or the data sheet for this MCU. If this is an oscillator fuse, you need to get rid of it. You're already using INTRC_IO.
Edit: I tried compiling and got an error: unknown keyword in #FUSES "XC". _________________ Vinnie Ryan |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Thu Mar 10, 2011 8:44 pm |
|
|
OH sorry that was something i added later. I changed it back to this
#fuses HS,INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,STOP=1)
its still outputting 0xFE ... its weird the faster it goes the higher the output it should be outputting 'x' but if i have it at 1M it outputs 0xff now that its at 4M it outputs 0xFE at 8M it outputs nothing via the uart.
thanks for reading ! _________________ Smart people know how stupid they are. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Fri Mar 11, 2011 3:36 am |
|
|
Understand that clock fuses are mutually exclusive. You can have INTRC_IO, _or_ HS, _not both_.....
Compiler version?.
There are some issues with timings on some of the 12 processors, and some compiler versions.
Best Wishes |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Fri Mar 11, 2011 7:16 am |
|
|
I have compiler 4.038, I'll try taking out the other fuse and just leave the intrc_io.
If there is a "issue" hopefully I can find a workaround. I really dont care what the clock is set too, I just need uart.
I wont be back till monday but i'll get some external xtals and see if that helps. but with the low pin count, using two pins for a xtal would make this chip almost useless.
thanks! _________________ Smart people know how stupid they are. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Fri Mar 11, 2011 8:17 am |
|
|
Ouch.
I'd say compiler problem then. 4.038, is 'pre' V4, really starting to work, and had some pretty fundamental problems. I 'keep' every compiler version that is used for working code. The earliest V4 compiler I kept, was a late 4.06x release, and this was about when things started to work....
Do you have/did you keep 3.249?. This was the 'working' release at this time, and is much more likely to give useable code.
Best Wishes |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Sun Mar 13, 2011 9:36 pm |
|
|
I got it working !! turns out its like twice the baud you specify. So if you specify your baud in the C #use rs232 as "4800" it will actually be "9600" and if you specify "9600" then it will be "19200" and so on. Least this is how it works in my situation.
Its working great with these settings. Thanks all.
Code: |
#include <12F615.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES IOSC8 //INTOSC speed 8MHz
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#use delay(clock=4000000)
#use rs232(baud=4800,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
|
Then in my UART tool (pickit2 tools) i set baud to 9600 and it works. _________________ Smart people know how stupid they are. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 13, 2011 11:51 pm |
|
|
Quote: | #include <12F615.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES NOPROTECT //Code not protected from reading
#FUSES IOSC8 //INTOSC speed 8MHz
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOPUT //No Power Up Timer
#use delay(clock=4000000)
#use rs232(baud=4800,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8)
|
You're running the PIC at 8 MHz, but then you're telling the compiler to
use delays as if the PIC is running at only 4 MHz. Because of this, all
your delays will be half as long as they should be. Since you're running
a software UART, if you specify it as 4800 baud, it will have delays that
make it run at 9600.
If you change your #use delay() statement so it matches the oscillator
speed specified in the #fuses statement, then you won't have to "fix" the
#use rs232() baud rate. You can specify the actual baud rate. |
|
|
zonemikel
Joined: 13 Oct 2007 Posts: 53 Location: Texas
|
|
Posted: Tue Mar 15, 2011 5:53 pm |
|
|
Just confirming it works exactly as pcm programmer said, thanks ! _________________ Smart people know how stupid they are. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|