CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Problems with RS232 and internal oscillator (PIC16F688)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mtar



Joined: 21 Sep 2005
Posts: 4

View user's profile Send private message

Problems with RS232 and internal oscillator (PIC16F688)
PostPosted: Wed Sep 21, 2005 9:04 am     Reply with quote

I've a problem with internal oscillator and the serial port of PIC16F688. When I use the external oscillator (8MHz), I can send from PIC normally with a velocity of 9600bps. When I don't connect the external quartz and relative condenser and I use the internal oscillator with this istructions:

#FUSES NOWDT, INTRC_IO, NOPROTECT, BROWNOUT, NOMCLR, NOCPD, NOPUT, IESO, FCMEN
#use delay(clock=8000000)
...
setup_oscillator( OSC_8MHZ );

I receive in Hyperterminal only byte 00.

I have tried to change the frequency to 4Mhz or to decrease the serial speed to 1200 and 2400, but the problem remains.

I use the PCWH 3.227 and MPLAB 7.21.

Thanks.

M.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 21, 2005 1:15 pm     Reply with quote

Post a complete (but short) test program that demonstrates the problem.
Guest








PostPosted: Wed Sep 21, 2005 5:07 pm     Reply with quote

Okay, this is the code for PIC16F688.
Thank you for your help!! M.

-------------------------------------------------------------------
Main firmware
-------------------------------------------------------------------

#include "C:\Programmi\PICC\acceleration.h"
#define INTS_PER_SECOND 30 // (8000000/(4*256*256))
BYTE int_count; // Number of interrupts left before a second has elapsed

// variable for the X Axis of accelerometer
float x;

// interrupt of 1 Hertz in order to send the X value of accelerometer
#int_rtcc
void clock_isr() {
// decrese and check the counter interrupt (for 1 Hertz)
if(--int_count==0) {
//reset counter
int_count=INTS_PER_SECOND;
// send accelleration data
printf("x,%0f\n\r",x);
}

}


void main() {
int value;

//----------------------------------------
setup_oscillator( OSC_8MHZ );
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_adc_ports(sAN4|sAN5|sAN6|sAN7|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(False);
//----------------------------------------

// value Volts converter (3.3V / 255 sample)
reference = 0.012941176;

// wait mechanical stabilization of sensor
delay_ms(4000);


// loop A/D
do {
// sample the x axis
set_adc_channel( 4 );
delay_us(10);
value = Read_ADC();
// convert to volts
x = (float)reference * (float)value;

// here there are other Axis...
// .....

delay_ms(10);
} while (TRUE);
}



-------------------------------------------------------------------
accelleration.h
-------------------------------------------------------------------

#include <16F688.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 NOBROWNOUT //No brownout reset
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOCPD //No EE protection
#FUSES PUT //Power Up Timer
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled

#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8)
Quote:
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 21, 2005 5:24 pm     Reply with quote

The line in your program shown below in bold should be removed.
Quote:
//----------------------------------------
setup_oscillator( OSC_8MHZ );
int_count=INTS_PER_SECOND;
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
setup_adc_ports(sAN4|sAN5|sAN6|sAN7|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_comparator(NC_NC);
setup_vref(FALSE);
setup_oscillator(False); <-- Remove this line
//----------------------------------------
Guest








PostPosted: Thu Sep 22, 2005 2:35 am     Reply with quote

Incredible, I was not really realized to have written again that istruction. That's why it worked only with the external oscillator… Thank you very much and excuse me for the ingenuity of this error…
Embarassed

Best regards
M.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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