|
|
View previous topic :: View next topic |
Author |
Message |
Andreas
Joined: 25 Oct 2004 Posts: 136
|
Processor Clock ???? |
Posted: Tue Aug 10, 2010 9:36 am |
|
|
Hi Friends
I am stuck with a simple problem which I couldn't solve thru hours, so now I am asking you if somebody can help.
I am using a 18F8720 PIC with a crystal of 7.372.000 Hz and now:
1. My baudrate is always just half of the requested baudrate.
2. The program is sending out the character but the LED at B5 is not blinking !
LED at B5 is always on ! Tested with a oscilloscope !
3. The character at the serial port should come every 200ms ???
but it comes every 100mS !!!
Here is my code, its really just this simple code !
Code: |
#include <18F8720.h>
#device ICD=TRUE
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //brownout reset
#FUSES BORV42 //Brownout reset at 4.2V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWAIT //Wait selections unavailable for Table Reads or Table Writes
#FUSES MCU //Microcontroller Mode
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#use delay(crystal= 7372000)
#define PIN_A0_DataLatch0 PIN_A0
#define PIN_A1_DataLatch1 PIN_A1
#define PIN_A2_DataLatch2 PIN_A2
#define PIN_A3_DataLatch3 PIN_A3
#define PIN_A5_DataLatch5 PIN_A5
#define Latch1 PIN_A0
#define Latch2 PIN_A1
#define Latch3 PIN_A2
#define Latch4 PIN_A3
#define Latch5 PIN_A4
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=com1,errors)
#int_TIMER1
void TIMER1_isr(void)
{
output_toggle(PIN_B4);
}
#int_TIMER3
void TIMER3_isr(void)
{
output_toggle(PIN_B3);
}
#int_RDA
void RDA_isr(void)
{
}
#int_TBE
void TBE_isr(void)
{
}
void main()
{
port_b_pullups(False);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_INTERNAL|T3_DIV_BY_8);
setup_timer_4(T4_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER3);
// enable_interrupts(INT_RDA);
// enable_interrupts(INT_TBE);
enable_interrupts(GLOBAL);
while(True)
{
output_high(PIN_B5);
delay_ms(100);
output_low(PIN_B5);
delay_cycles(100);
fputc('A',com1);
}
}
|
I hope somebody can give me a hint, all ideas very appreciated.
Best regards out of vienna, Austria.
Andreas |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Aug 10, 2010 11:08 am |
|
|
Code: | while(True)
{
output_high(PIN_B5);
delay_ms(100);
output_low(PIN_B5);
delay_cycles(100);
fputc('A',com1);
}
} |
Well this is what you asked for.
B5 goes high ( led goes on)
100 ms elapses
B5 goes low
100 cycles elapse at 7 mhz this is a very very very short time
"A" prints out at 19200 baud say it takes 1 ms
then pin b5 goes high
From the point of view of pin b5 it is only off for about 1ms but is on for 100ms. 100ms plus 100 cycles is approx 100ms so "A" prints every approx 100msLooks like you got what you coded |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 10, 2010 11:21 am |
|
|
Quote: |
#include <18F8720.h>
#FUSES XT
#use delay(crystal= 7372000)
|
Also, XT is the wrong fuse for a 7.372 MHz crystal. The 18F8720 data
sheet specifies that XT is only for 4 MHz, maximum. You should use
the HS fuse. I'm surprised the PIC even runs. I think you might be
testing this in Proteus. |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Tue Aug 10, 2010 2:28 pm |
|
|
Hello Douglas,
Yes You are right, I have overseen that I didn't changed the delay statement, Thanks.
Sometimes one is blind to see such easy cases
Hello PCM Programmer,
Yes, but the funny thing was, that even changing the Osc Settings didn't affect the baudrate, but as easy it is sometimes, it started out to work now perfectly, unfortunately I can't remember what changes made it work.....
Many Thanks for the quick replies
With best regards
Andreas |
|
|
|
|
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
|