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 CCS Technical Support

PIC12F683 Upgrade

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



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PIC12F683 Upgrade
PostPosted: Mon Sep 11, 2006 9:52 pm     Reply with quote

I have an existing board that currently use the PIC12F675. I would like to add some floating point math by adding a PIC12F683. I have the following code that I am using with the PIC12F675 but have added the Floating Point math.

Can someone with more experience with the PIC12F683 tell me what I am doing wrong in my code? I am running PCWH version 3.205

/* Code Below

#include <12f683.h>
#device adc=10
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD
#use rs232( baud=9600, xmit=PIN_A5 )

long ad = 0;
float temp = 0;
float lowbat = 0;

void init(void) // Hardware initialization
{
set_tris_a( 0x1f );
setup_adc_ports( AN0_ANALOG );
setup_adc_ports( AN2_ANALOG );
setup_adc(ADC_CLOCK_DIV_8);
setup_comparator( NC_NC_NC_NC );

output_high(PIN_A4);
delay_ms( 5 );
output_low(PIN_A4);
delay_ms( 500 );
}

void main()
{
init(); // Configure peripherals/hardware
while(1) // Continuous loop
{
// check thermocouple sensor data
set_adc_channel( 0 ); // Set AD channel to AN0
delay_us(20);

ad = read_adc(); // Read A/D channel 0 or AN0 into ad variable

temp = (float)ad * (5.0/1023); // Convert 10-bit reading
temp = (float)temp / 100;
temp = (float)temp * 1.8 + 32;

printf("%6.2fF\r\n",temp);
delay_ms(500);

// check battery voltage for < 3.6V if so send l for low battery
set_adc_channel( 2 ); // Set AD channel to AN2
delay_us(20);

ad = read_adc(); // Read A/D channel 2 or AN0 into ad variable

lowbat = (float)ad * (5.0/1023); // Convert 10-bit reading
if ( lowbat <= 3.6 )

printf("lb\r\n");
delay_ms(500);
}
}

/* End code

Thanks in advance,

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 11, 2006 10:19 pm     Reply with quote

First, the #use delay() statement should go after the #fuses statement,
as shown in bold below. Then the compiler will automatically insert code
to setup the OSCCON register to the correct frequency. It worked for
you anyway, because the power-on reset state of OSCCON is for 4 MHz.
But if you ever want to use a different frequency for the internal
oscillator, then it's important to put #use delay() after #fuses.
Quote:
#include <12f683.h>
#device adc=10
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD
#use delay(clock=4000000)
#use rs232( baud=9600, xmit=PIN_A5 )


In your init() function below, you don't need to set the TRIS because
you're using the default "standard i/o" mode of the compiler, and it
will automatically set the correct TRIS in that mode, as long as you
use CCS i/o functions (which you are doing).
The 2nd problem below is in your Port A setup. You don't setup the A/D
pins with sequential statements. If you do that, only the last statement
will take effect. If you want more than one Analog pin enabled, you
need to bitwise OR the constants together, as shown in bold below.
The constants come from the 12F683.H file. I installed vs. 3.205 and
verified this.
Quote:
void init(void) // Hardware initialization
{
//set_tris_a( 0x1f );
//setup_adc_ports( AN0_ANALOG );
//setup_adc_ports( AN2_ANALOG );

setup_adc_ports(sAN0 | sAN2);
setup_adc(ADC_CLOCK_DIV_8);
setup_comparator( NC_NC_NC_NC );

output_high(PIN_A4);
delay_ms( 5 );
output_low(PIN_A4);
delay_ms( 500 );
}

There might be other problems, but these were the immediate ones
that I saw.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 4:57 am     Reply with quote

I will make the changes and give it another try this evening! Thanks for the reply!

Scott
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 2:47 pm     Reply with quote

I have been trying to test the code but nothing happens. The code works with the PIC12F675 but I cannot add Float or any other code. I have also noticed that the PIC12F683 gets very very hot! Any thoughts?

I must get this complete tonight to ship tomorrow!

Thanks for your help,

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 3:03 pm     Reply with quote

If the PIC gets hot, then check the connections. Check if you reversed
power and ground. If you did, that PIC might be destroyed.
newguy



Joined: 24 Jun 2004
Posts: 1909

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 3:03 pm     Reply with quote

If the chip gets hot,

(a) check your connections, especially the pinout of the new processor and if it differs from the old one, and

(b) try a new chip.

Chips usually only get hot if they're damaged or if you have power & ground wrong. Especially a PIC. I've never had one that ran even remotely warm.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 3:30 pm     Reply with quote

The PIC12F683 and the old PIC12F675 are pin for pin compatible! Unless I am missing something. I have never had this issue before.

Can someone supply me with a simple example they have compiled for the PIC12F683 with GPIO.0 as analog and send the value over GPIO.5 non-inverted?

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 3:44 pm     Reply with quote

I don't have a 12F683 chip to test. I only have a 12F675 and a 12F629.

I still say that if the PIC is getting very hot, then you have a problem.
You may have +5v directly connected to an i/o pin that's set at a logic
low level with an output_low() statement. That would likely make the
PIC become very hot. Until that problem is corrected, getting new code
won't help.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 4:22 pm     Reply with quote

It seems that PIN AN2 which is monitoring the battery is making the chip get hot. I have folded the pin up and the chip does not get hot.

Here is my code for the PIC12F675:
#include <12f675.h>
#device adc=10
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,NOBROWNOUT,NOMCLR,NOCPD
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_A5)

long ad = 0;
float volts = 0;

void init(void) // Hardware initialization
{

setup_adc_ports( sAN0 ); // A/D module on for GPIO.0
setup_adc( ADC_CLOCK_DIV_8 ); // A/D clock/8 @4MHz,Tad=2uS
setup_comparator( NC_NC_NC_NC ); // disable comparator module

output_high(PIN_A4);
delay_ms( 5 );
output_low(PIN_A4);
delay_ms( 500 );

}

void main()
{
init(); // Configure peripherals/hardware
while(1) // Continuous loop
{
set_adc_channel( 0 );
delay_us(20);
ad = read_adc(); // Read A/D channel into ad variable
volts = (float)ad * (5.0/1023) ; // Convert 10-bit reading

printf("%6.2f\r\n",volts);
delay_ms(2000); // Pause 50mS between updates
}
}

It seems I should be able to change #include <12f675.h> to #include <12f683.h> and it should work.

The above code works fine and I am receiving the Analog value via serial port.

Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 4:36 pm     Reply with quote

Your version of the compiler is buggy with the 12F683.

Here is one of the problems, and a fix for it:
http://www.ccsinfo.com/forum/viewtopic.php?t=25417

There might be other problems.
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

PostPosted: Tue Sep 12, 2006 5:01 pm     Reply with quote

It's working! Thanks for your help!

I will work on the remaining problem with AN2 making the PIC hot. The battery is a 3.6V battery so it should be ok. The problem may be that the A/D is latching. I may go ahead and add a 1K ohm resistor between the Battery and AN2.

Scott
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