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

16f88 reset problem using ADC

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



Joined: 27 Jun 2006
Posts: 39

View user's profile Send private message

16f88 reset problem using ADC
PostPosted: Tue Jul 18, 2006 3:20 pm     Reply with quote

Hello,
I have written the following code to read ADC values and drive an output driver and post lcd status bits. There seems to be some sort of a reset issue caused by code or programming??? I have programmed about 5 chips, some reset in a loop in less than a second, some run for up to 10 mins with out reseting. I am wondering if i am overlooking something in my code, or if there may be a programmer issue???

I have done the following to try and debug the problem
-programmed 10 microcontrollers, all still have reset issues at different lengths in time
-upgraded to the most recent PUM firmware on PICstart plus.
-reset COM setting to, hardware control, fifo disabled.
-disabled function calls to see if it is a given function causing the problem.
-turned on/off certain fuses to see if would help

Thank you for you patience, as this is my first PICC project. Please let me have it as to anything i might do different in my coding. Thanks for any suggestion.


Code:
//reading adc values 10 bit and eval threshold for tilt control
#include <16F88.h>
#device ADC=10
#use delay(clock=8000000)
#fuses INTRC_IO,NOWDT,NOPUT,NOMCLR,BROWNOUT,NOLVP,NOPROTECT,NOCPD//nolvp for lcd
#fuses NOFCMEN,NOIESO,
#use fixed_io(a_outputs=PIN_A2, PIN_A3,PIN_A4,PIN_A5,PIN_A6,PIN_A7)//all other port pins are fixed inputs
#define TRled PIN_B0//tilt LED pins
#define TLled PIN_B6
#define TUled PIN_A6
#define TDled PIN_A7
#define Driver1 PIN_A2//driver pins
#define Driver2 PIN_A3
#define Driver3 PIN_A4
#define Driver4 PIN_B7
#define Status1 PIN_B1//lcd status pins
#define Status2 PIN_B2
#define Status3 PIN_B3
#define Status4 PIN_B4
#define Status5 PIN_B5


//loop LED's on boot_______________________________________________________________
void bootLoop(int i){
int j;
   for(j=1;j<=i;j++)
   {
   //CCW loop
   OUTPUT_HIGH(TRled);
   DELAY_MS(50);
   OUTPUT_LOW(TRled);
   OUTPUT_HIGH(TUled);
   DELAY_MS(50);
   OUTPUT_LOW(TUled);
   OUTPUT_HIGH(TLled);
   DELAY_MS(50);
   OUTPUT_LOW(TLled);
   OUTPUT_HIGH(TDled);
   DELAY_MS(50);
   OUTPUT_LOW(TDled);
   
   //CW loop
   OUTPUT_HIGH(TRled);
   DELAY_MS(50);
   OUTPUT_LOW(TRled);
   OUTPUT_HIGH(TDled);
   DELAY_MS(50);
   OUTPUT_LOW(TDled);
   OUTPUT_HIGH(TLled);
   DELAY_MS(50);
   OUTPUT_LOW(TLled);
   OUTPUT_HIGH(TUled);
   DELAY_MS(50);
   OUTPUT_LOW(TUled);
   }
}//function


//Flash LED's on boot___________________________________________
void bootFlash(int i){
int j;
   for(j=1;j<=i;j++)
   {
   OUTPUT_HIGH(TDled);
   OUTPUT_HIGH(TUled);
   OUTPUT_HIGH(TLled);
   OUTPUT_HIGH(TRled);
   DELAY_MS(50);
   OUTPUT_LOW(TDled);
   OUTPUT_LOW(TUled);
   OUTPUT_LOW(TLled);
   OUTPUT_LOW(TRled);
   DELAY_MS(50);
   }
}

//ADC Tilt _______________________________________________
void ADC_TEval(*tilt,*heat){
long int Tvalue;
//read adc value
SET_ADC_CHANNEL(0);
DELAY_US(10);
Tvalue  = READ_ADC(ADC_START_AND_READ);
if (Tvalue>1015) //tilt down
{
//set led's
OUTPUT_HIGH(TDled);
OUTPUT_LOW(TUled);
OUTPUT_LOW(TLled);
OUTPUT_LOW(TRled);
//set drivers
OUTPUT_LOW(Driver1);
OUTPUT_LOW(Driver2);
OUTPUT_HIGH(Driver3);
//lcd status pins
OUTPUT_LOW(Status5);
OUTPUT_LOW(Status4);
OUTPUT_HIGH(Status3);
OUTPUT_LOW(Status2);
OUTPUT_LOW(Status1);//4-TD-on   
}      
else if (Tvalue>991)//tilt up
{
//set led's
OUTPUT_HIGH(TUled);
OUTPUT_LOW(TDled);
OUTPUT_LOW(TLled);
OUTPUT_LOW(TRled);
//set drivers
OUTPUT_HIGH(Driver1);
OUTPUT_HIGH(Driver2);
OUTPUT_LOW(Driver3);
//lcd status pins
OUTPUT_LOW(Status5);
OUTPUT_LOW(Status4);
OUTPUT_LOW(Status3);
OUTPUT_HIGH(Status2);
OUTPUT_HIGH(Status1);//3-TU on
}
else if (Tvalue>950)//tilt left
{
//set led's
OUTPUT_HIGH(TLled);
OUTPUT_LOW(TUled);
OUTPUT_LOW(TDled);
OUTPUT_LOW(TRled);
//set drivers
OUTPUT_LOW(Driver1);
OUTPUT_HIGH(Driver2);
OUTPUT_HIGH(Driver3);
//lcd status pins
OUTPUT_LOW(Status5);
OUTPUT_LOW(Status4);
OUTPUT_LOW(Status3);
OUTPUT_HIGH(Status2);
OUTPUT_LOW(Status1);//2-TL on
}
else if (Tvalue>915)//tilt right
{
//set led's
OUTPUT_HIGH(TRled);
OUTPUT_LOW(TUled);
OUTPUT_LOW(TLled);
OUTPUT_LOW(TDled);
//set drivers
OUTPUT_HIGH(Driver1);
OUTPUT_LOW(Driver2);
OUTPUT_LOW(Driver3);
//lcd status pins
OUTPUT_LOW(Status5);
OUTPUT_LOW(Status4);
OUTPUT_LOW(Status3);
OUTPUT_LOW(Status2);
OUTPUT_HIGH(Status1);//1-TR on
}
else if (Tvalue<915)//all switches off/check if heat should be on
{   //set led's
//sets indicator led's low regardless of heat state/turns drivers off
OUTPUT_LOW(TDled);
OUTPUT_LOW(TUled);
OUTPUT_LOW(TLled);
OUTPUT_LOW(TRled);
//set drivers
OUTPUT_LOW(Driver1);
OUTPUT_LOW(Driver2);
OUTPUT_LOW(Driver3);
   if (*heat==0){//turns lcd status pins low if heat is off
   //lcd status pins
   OUTPUT_LOW(Status5);
   OUTPUT_LOW(Status4);
   OUTPUT_LOW(Status3);
   OUTPUT_LOW(Status2);
   OUTPUT_LOW(Status1);//all low
   }
   else if (*heat==1){
   //lcd status pins - heat on - 4 if heat status is on
   OUTPUT_LOW(Status5);
   OUTPUT_LOW(Status4);
   OUTPUT_HIGH(Status3);
   OUTPUT_LOW(Status2);
   OUTPUT_HIGH(Status1);//5-heater on
   }
}//else if
}//function

//ADC Heater________________________________________________
void ADC_HEval(*tilt,*heat){
long int Hvalue; //10 bit adc value
//setup ADC
SET_ADC_CHANNEL(1);
DELAY_US(10);
Hvalue  = READ_ADC(ADC_START_AND_READ);

//eval
if (Hvalue>930)//heater button pushed
{
   if (*heat==0)//heat was off
   {
      DELAY_MS(500);
      Hvalue  = READ_ADC(ADC_START_AND_READ);
      if(Hvalue>930)//recheck pushbutton
      {OUTPUT_HIGH(Driver4);
      *heat = 1;
      //lcd status pins
      OUTPUT_LOW(Status5);
      OUTPUT_LOW(Status4);
      OUTPUT_HIGH(Status3);
      OUTPUT_LOW(Status2);
      OUTPUT_HIGH(Status1);//5-heater on
      }
      else
      {OUTPUT_LOW(Driver4);
      }
   }
   else if (*heat==1)//heat was on
   {
      DELAY_MS(500);
      Hvalue  = READ_ADC(ADC_START_AND_READ);
      if(Hvalue>930)//recheck if still pushed
      {OUTPUT_LOW(Driver4);
      *heat = 0; //heat flag off
      }
   }
}//if
}//function

//Main  _______________________________________________
void main() {
int heat, tilt;

//setup adc Params------------------------
setup_oscillator(OSC_8MHZ);//sets internal osc multiplier
SETUP_ADC_PORTS(sAN0|sAN1|VSS_VDD );//set RA0 RA1 as analog
SETUP_ADC(ADC_CLOCK_DIV_16);
//initialize vars/outputs----------------
OUTPUT_B(0X00);//clear portb 0
OUTPUT_A(0X00);//clear porta 0
heat = 0;//status of heat led
tilt = 0;//status of tilt led

//flash led's on boot, input # of cycles------------------------
bootLoop(2);
bootFlash(7);

while(1){
//adc Loops-------------------------------------
ADC_TEval(&tilt,&heat);
ADC_HEval(&tilt,&heat);

DELAY_MS(10); //pace cycles, reduce noisy jitter

}//while
}//main

[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 18, 2006 4:10 pm     Reply with quote

I notice that you're turning on several LEDs and other circuits,
and you also have the Brownout fuse enabled. It's possible
that your power supply is poor and it's being loaded down to
below +5v. Brownout reset can trigger at 4.35v, according
to the 16F88 data sheet. So check your power supply.

Also make sure the MCLR pin is connected to +5v with a 10K resistor.
(Use 47K if you're using the CCS ICD-U40).

A few other comments:

1. Normally, the #use delay() statement should be placed on the
next line after the #fuses statement, not above it.

2. The standard for coding style in C, is to put constants in upper case
and to put function names in lower case (or mixed case). You have
done it the opposite of the standard, so it makes your code harder
to read.


Also, what is your version of the compiler ? It's possible that if you
have an early version, there could be some problems. The version
number will be something like 3.236, or 3.249, etc.
fvnktion



Joined: 27 Jun 2006
Posts: 39

View user's profile Send private message

PostPosted: Tue Jul 18, 2006 4:33 pm     Reply with quote

Thanks for the comments PCM,

I have made changes to the brownout, and placing the #use delay, getting the same results.
-the version of compiler is: 3.203

Also, i have run the IC on both a proto board, and PCB with the same results using different high output power supplies. I am using a an st 5v regulator to power the IC.

I will try and tie mclr high first thing in the morning.... Is it still sensitive while using the nomclr fuse??

Thanks,

Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 18, 2006 4:41 pm     Reply with quote

Actually, I missed that you had the NOMCLR fuse. In that case
you don't need the MCLR resistor.

I'll install vs. 3.203 and look at the .LST file.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 18, 2006 5:58 pm     Reply with quote

I looked at the start-up code for PCM vs. 3.203, and there are two
problems with the setup for the ADCON0 and ANSEL registers.
However, your calls to setup_adc_ports() and setup_adc() quickly
fix those problems. The comparator is disabled by default upon
power-on reset, so I don't think there is any comparator problem.

Read these threads, which are about the problem of random resets:
http://www.ccsinfo.com/forum/viewtopic.php?t=25903
http://www.ccsinfo.com/forum/viewtopic.php?t=26648
http://www.ccsinfo.com/forum/viewtopic.php?t=26557
Try everything listed in those threads, including the restart_cause() test.

Make sure you have NOLVP and NOWDT in your #fuses statement.


Additional things to try:

1. Disconnect all external circuits except one (maybe an LED) and
see if you still get the problem.
fvnktion



Joined: 27 Jun 2006
Posts: 39

View user's profile Send private message

PostPosted: Wed Jul 19, 2006 11:20 am     Reply with quote

solved.......

Thanks for all you help PCM. I worked with the restart_cause function and did numerous recode efforts before deciding to play with the placement of the capacitor. When soldering a .100 uf cap directly to the PIC pins on the PCB, the problem was immediately solved. Apparently the existing caps on the board were not close enough, sheesh high maintenance f88, jk.

Just want to say thanks so much, I don't know what we would all do without all of your speedy help!
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