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

12f1822 resetting
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

12f1822 resetting
PostPosted: Wed Jul 13, 2011 1:05 pm     Reply with quote

Hello all,

I am using compiler 4.120 along with a 12f1822.

I appear to be having reset issues.

Here is the code:

Code:

#include "12F1822.h"

#Fuses INTRC_IO,WDT,NOPROTECT,NOMCLR,NOBROWNOUT,PUT,NOIESO,NOFCMEN,NOCPD,NOSTVREN,NOCLKOUT,NODEBUG
#device adc = 10              // 10-bit resolution for Analog-Digital Conversion
#use delay (CLOCK=4000000)    // Set Clock to 4 MHz
#define LOWLEVEL LOWLIMIT+1000
//-------------------------INCLUDES---------------------------------------------
#include "PINOUT_12f1822.c"          // general pinout

//--------------------------GLOBALS---------------------------------------------
unsigned long a2dval;
unsigned long LOWLIMIT;
long EEPROM_START_ADDRESS = 0;
//--------------------------EEPROM ADDRESSING-----------------------------------
#define INIT_DONE  0xDD     //flag to signify that initialzation routine is done
#define INIT_DONE_FLAG_ADDR 0x00     // address for storing initialization data
//--------------------------PREPROCESSOR DIRECTIVES-----------------------------
void initialize(void);
unsigned long set_threshold(void);
unsigned long read_a2d(unsigned char channel);
unsigned long filter_a2d(unsigned char channel);

void main ()
{     
    int i = 0;
 
    #byte STATUS = 0x003
    #byte PCON = 0x096
 
    initialize();
    delay_ms(1000);
    LOWLIMIT = set_threshold();
    output_high(LED);
    setup_wdt(WDT_128S);    // additional warmup
    delay_ms(50);
    sleep();
    delay_cycles(10);

    //BEEP:
    i = 0;
    output_low(LED);
    set_pwm1_duty(20);     //TONE 1
    delay_ms(300);
    restart_wdt();
    printf("\nDONE\n\r");
    output_high(LED);
    set_pwm1_duty(50);     //TONE 2
    delay_ms(250);
    restart_wdt();
    printf("\nDONE\n\r");
    output_low(LED);
    set_pwm1_duty(80);     //TONE 3
    delay_ms(200);
    restart_wdt();
    printf("\nDONE\n\r");
    set_pwm1_duty(0);
    output_high(LED);
    i++;
    delay_ms(100);
   
    setup_wdt(WDT_4S);                       //set watch-dog timer for 4 seconds
    while (true)
    { 
        output_high(LED);
        restart_wdt();
        a2dval = filter_a2d(3);
        restart_wdt();
        delay_ms(500);
        restart_wdt();
       
        if(a2dval >= LOWLEVEL)
        {
            setup_wdt(WDT_OFF);
            output_high(LED);
            restart_wdt();
            set_pwm1_duty(100);
            restart_wdt();
            delay_ms(100);
            printf("\n%4Lu\n\r",a2dval);
            restart_wdt();
        }
        else                                    //take a reading every 4 seconds
        {
            output_low(LED);
            set_pwm1_duty(0);
            printf("\n%4Lu\n\r",a2dval);
            restart_wdt();
            delay_ms(500);
            sleep();
            delay_cycles(10);
            output_high(LED);
        }   
     }     
}

void initialize (void)
{
    setup_wdt(WDT_2S);            //switch fuse from NOWDT to WDT
    setup_oscillator(OSC_4MHZ);
    setup_ADC_PORTS(sAN3|VSS_VDD);
    delay_ms(20);
    setup_adc(ADC_CLOCK_DIV_16);  // Set A2D clock
    delay_ms(20);
    set_adc_channel(3);           // Set inital A2D pin (A3)
    delay_ms(20);
    restart_wdt();
    read_adc(ADC_START_ONLY);
    delay_ms(100);
    setup_ccp1(CCP_PWM);
    setup_TIMER_2 (T2_DIV_BY_4, 255,1);
    set_pwm1_duty(0);
    restart_wdt();
   
    #byte ADCON0 = 0x09D
    ADCON0 = 0b00011001;
    #byte ADCON1 = 0x09E
    ADCON1 = 0b10110000;
    #byte ANSELA = 0x18C
    ANSELA = 0b00000000;           //no analogs on A SELA
    #byte ANSELC = 0x18E
    ANSELC = 0b00001000;           //set to channel 3
}

unsigned long set_threshold(void)
{
    int16 i = 0;
    printf("\nINIT: %02x\n\r",read_eeprom(INIT_DONE_FLAG_ADDR));
    if(read_eeprom(INIT_DONE_FLAG_ADDR) != INIT_DONE)
    {
        i = 0;
        set_pwm1_duty(0);              //turn off alarm
        setup_wdt(WDT_256S);           //set watch-dog timer minutes
        sleep();
        delay_cycles(10);
        while (i<4)                    //total initialization is ~ 17.06 minutes
        { 
            a2dval = filter_a2d(3);
            restart_wdt();
            delay_ms(600);
            output_high(LED);
            set_pwm1_duty(0);
            printf("\ninitial:  %lu: %4Lu\n\r",i,a2dval);
            i++;
            sleep();
            delay_cycles(10);
        }
        // Record 0ppm value into memory and set initialization flag:
        EEPROM_START_ADDRESS = INIT_DONE_FLAG_ADDR;
        write_eeprom(EEPROM_START_ADDRESS,INIT_DONE);
        write_eeprom(EEPROM_START_ADDRESS+1,(a2dval & 0xFF00)>>8);
        write_eeprom(EEPROM_START_ADDRESS+2,(a2dval & 0x00FF));
        printf("\nLOWLEVELr:   %4Lu\n\r",a2dval);
        a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1)) <<8;     //upper 2 bytes
        a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
        printf("\nLOWLEVELe: %4Lu\n\r",a2dval);

    }
    else
    {
        a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1))<<8;     //upper 2 bytes
        a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
        printf("\nLOWLEVELe: %4Lu\n\r",a2dval);
        i = 0;
        set_pwm1_duty(0);              //turn off alarm
        setup_wdt(WDT_64S);          //set watch-dog timerminutes
        sleep();
        delay_cycles(10);
        while (i<4)                    //total initialization is ~5.33 minutes
        { 
            a2dval = filter_a2d(3);
            delay_ms(600);
            output_high(LED);
            set_pwm1_duty(0);
            printf("\n%lu: %4Lu\n\r",i,a2dval);
            i++;
            sleep();
            delay_cycles(10);
        }
       
    }
    a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1)) <<8;     //upper 2 bytes
    a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
    return a2dval;   // return base value from initial zeroing stored in memory
}

unsigned int16 read_a2d(unsigned char channel){

  unsigned int16 ADC_result;

  channel&=0x07;   // truncate channel to 3 bits
   
  #byte ADCON0 = 0x09D
  #byte ADRESH = 0x09C
  #byte ADRESL = 0x09B
  restart_wdt();
  ADCON0=0x01;             
  ADCON0|=(channel<<2);   
  delay_us(50);
  ADCON0|=0x02;       //start conversion
  while(BIT_TEST(ADCON0,1))continue; 
  restart_wdt();
  ADC_result = 0x0000;
  ADC_result += ADRESH;
  ADC_result <<= 8;
  ADC_result += ADRESL;
 
  return(ADC_result);   // return result
}

unsigned int16 filter_a2d(unsigned char channel)
{
   int i;                         
   unsigned int16 min= 2000;  // min value is set far out of range of adc
   unsigned int16 max= 0;
   unsigned int16 avg = 0;
   unsigned int16 val = 0;
   
   restart_wdt();
   set_adc_channel(channel);
   delay_us(20);
   for (i=1; i<=7; ++i)
   {
       restart_wdt();
       val = read_a2d(channel);
       restart_wdt();
       delay_us(20);
       max = (val>=max)?val:max;
       min = (val<min)?val:min;
       avg += val;
   }
   avg = ((avg - max) - min);
   delay_us(20);
   return(avg/5);
}


I have a single sensor that requires a warmup for taking reading...

Throughout the code I am using WDT's and as can be seen i have added many kicks to verify this is not the cause of the resets...

I AM using an external pullup on MCLR (10k) and have tried various combinations of fuses for MCLR, BOR, stack overflow/underflow, etc...

I am still recieving periodic resets.

I have reviewed the errata sheet and there are bugs with the BOR and ADC that could cause this.

Has anyone else ran into these resets with this chip??

I would like to possibly check the PCON and STATUS registers to trace the cause of the resets, but am not sure how to do this yet. I could print the registers as a first step, but i am not sure if they will be accurate, or if they will change by the time my 'initialize' routine is performed.

I wish there was an interrupt on reset available so that I could print out the registers upon reset and see the cause...

Any suggestions would be very appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 1:28 pm     Reply with quote

Quote:

#Fuses INTRC_IO,WDT,NOPROTECT,NOMCLR,NOBROWNOUT,PUT,
NOIESO,NOFCMEN,NOCPD,NOSTVREN,NOCLKOUT,NODEBUG


You must use the WDT_SW fuse if you want to enable/disable the WDT
under program control. This is explained in this section of the 12F1822
data sheet:
Quote:

10.2 WDT Operating Modes
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

WDT_SW
PostPosted: Wed Jul 13, 2011 1:33 pm     Reply with quote

I will change this to WDT_SW...

I have not seen a problem with my WDT yet, as far as i am aware, and it seems to be going to sleep and waking up as predicted.
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

ADC conversion
PostPosted: Wed Jul 13, 2011 2:31 pm     Reply with quote

lemme ask you this:

The Errata for the 12f1822 states:

Quote:
Select the dedicated RC oscillator as the ADC conversion clock source, and perform all conversions with the device in Sleep.


would it be better in this case to use ADC_CLOCK_INTERNAL in the setup, and perform all of the conversions in sleep?

I am definately not accustomed to that...

Question

i could also add a watchdog restart in the ADC while loop that is waiting for the conversion to finish... but is this wise ? i dont want a hang-up.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 13, 2011 3:05 pm     Reply with quote

First, find out what the PIC reports as the reason for the reset.
Call the restart_cause() function at the very beginning of main() before
you do anything else. This means before calling your init routine or
anything. Display the hex byte with printf as the next line after that.
Then wait for the PIC to do a reset. Look at the displayed byte to
see the reason.

Example:
Quote:

c:\program files\picc\examples\ex_wdt18.c

That example tries to interpret the result. You can do that, but I think it's
also a good idea to print the raw hex byte that is returned by restart_cause().


Links to threads on random resets:
http://www.ccsinfo.com/forum/viewtopic.php?t=27638&start=4
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Jul 14, 2011 2:08 am     Reply with quote

The erratum for the 1822, on the ADC, is _foul_. It really means the chip is not properly functional in this area. Crying or Very sad

Using sleep is possible, or the other bodge-around they give (manually timing). Start by proving what the restart cause is though, as PCMprogrammer outlines. If it returns WDT timeout, then the odds are the ADC conversions is getting hung by the erratum.
Given you are not using interrupts, either bodge would be useable. With interrupts either is going to involve a lot of work.

Why are you manually setting up the ADC, and the conversions?. Does the CCS code not work?.

I have in the past posted basic CCS code for using the sleep conversion, and this should be findable with a search.
This is probably easier to code than the timing bodge.
I must admit I'd be inclined to select another chip, given just how bad the fault is, and save a lot of work.

Best Wishes
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

manual adc
PostPosted: Thu Jul 14, 2011 7:06 am     Reply with quote

The reason that I had chosen to do a manual ADC conversion is because I had previously been using version 4.114 and the ADC was not properly setup for this chip... Now that i am on 4.120, I believe alot has been fixed, but I saw that it was working so I left it as is.

I will try to find the cause, and set the posting... in the meanwhile i will also search for your posts on performing the ADC in sleep...

thanks again guys you are great.
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

changes and causes
PostPosted: Thu Jul 14, 2011 8:26 am     Reply with quote

as per a few threads i followed, here are the changes I have made:

Code:

#include "12F1822.h"

#Fuses INTRC_IO
#Fuses WDT_SW
#Fuses NOPROTECT
#Fuses NOMCLR
#Fuses NOBROWNOUT
#Fuses PUT
#Fuses NOIESO
#Fuses NOFCMEN
#Fuses NOCPD
#Fuses NOSTVREN
#Fuses NOCLKOUT
#Fuses NODEBUG
#Fuses NOLVP

//#FUSES NONE
//#rom 0x8007 = {0x25B9, 0x3CFF}  //can hardcode the fuses
#device adc = 10              // 10-bit resolution for Analog-Digital Conversion
#use delay (CLOCK=4000000)    // Set Clock to 4 MHz
#define LOWLEVEL LOWLIMIT+1000
//-------------------------INCLUDES---------------------------------------------
#include "PINOUT_12f1822.c"          // general pinout

//--------------------------GLOBALS---------------------------------------------
unsigned long a2dval;
unsigned long LOWLIMIT;
long EEPROM_START_ADDRESS = 0;
//--------------------------EEPROM ADDRESSING-----------------------------------
#define INIT_DONE  0xDD     //flag to signify that initialzation routine is done
#define INIT_DONE_FLAG_ADDR 0x00     // address for storing initialization data
//--------------------------PREPROCESSOR DIRECTIVES-----------------------------
void initialize(void);
unsigned long set_threshold(void);
unsigned long filter_a2d(unsigned char channel);

void main ()
{   
   
    printf("RESTART CAUSE: %x", restart_cause());
    int i = 0;
    initialize();
    delay_ms(1000);
    LOWLIMIT = set_threshold();
    output_high(LED);
    setup_wdt(WDT_128S);    // additional warmup for ~2.13 min
    delay_ms(50);
    sleep();
    delay_cycles(10);
 
    //BEEP:
    i = 0;
    output_low(LED);
    set_pwm1_duty(20);     //TONE 1
    delay_ms(300);
    restart_wdt();
    printf("\nDONE\n\r");
    output_high(LED);
    set_pwm1_duty(50);     //TONE 2
    delay_ms(250);
    restart_wdt();
    printf("\nDONE\n\r");
    output_low(LED);
    set_pwm1_duty(80);     //TONE 3
    delay_ms(200);
    restart_wdt();
    printf("\nDONE\n\r");
    set_pwm1_duty(0);
    output_high(LED);
    i++;
    delay_ms(100);
   
    setup_wdt(WDT_4S);                       //set watch-dog timer for 4 seconds
    while (true)
    { 
        output_high(LED);
        restart_wdt();
        a2dval = filter_a2d(3);
        restart_wdt();
        delay_ms(500);
        restart_wdt();
       
        if(a2dval >= LOWLEVEL)
        {
            setup_wdt(WDT_OFF);
            output_high(LED);
            restart_wdt();
            set_pwm1_duty(100);
            restart_wdt();
            delay_ms(100);
            printf("\n%4Lu\n\r",a2dval);
            restart_wdt();
        }
        else                                    //take a reading every 4 seconds
        {
            output_low(LED);
            set_pwm1_duty(0);
            printf("\n%4Lu\n\r",a2dval);
            restart_wdt();
            delay_ms(500);
            sleep();
            delay_cycles(10);
            output_high(LED);
        }   
     }     
}

void initialize (void)
{
    enable_interrupts(GLOBAL);     
    enable_interrupts(INT_AD);      //allow A-D conversion to wakeup chip
    clear_interrupt(INT_AD);       //clear the conversion so chip can sleep
    setup_oscillator(OSC_4MHZ);
    setup_ADC_PORTS(sAN3|VSS_VDD);
    delay_ms(20);
    setup_adc(ADC_CLOCK_INTERNAL);  // Set A2D clock
    setup_wdt(WDT_2S);              //switch fuse from NOWDT to WDT
    delay_ms(20);
    set_adc_channel(3);             // Set inital A2D pin (A3)
    delay_ms(20);
    restart_wdt();
    read_adc(ADC_START_ONLY);
    delay_ms(100);
    clear_interrupt(INT_AD);       //clear the conversion so chip can sleep
    setup_ccp1(CCP_PWM);
    setup_TIMER_2 (T2_DIV_BY_4, 255,1);
    set_pwm1_duty(0);
    restart_wdt();
   
    #byte ADCON0 = 0x09D
    ADCON0 = 0b00011001;
    #byte ADCON1 = 0x09E
    ADCON1 = 0b10110000;
    #byte ANSELA = 0x18C
    ANSELA = 0b00000000;           //no analogs on A SELA
    #byte ANSELC = 0x18E
    ANSELC = 0b00001000;           //set to channel 3
}

unsigned long set_threshold(void)
{
    int16 i = 0;
    printf("\nINIT: %02x\n\r",read_eeprom(INIT_DONE_FLAG_ADDR));
    if(read_eeprom(INIT_DONE_FLAG_ADDR) != INIT_DONE)
    {
        i = 0;
        set_pwm1_duty(0);              //turn off alarm
        setup_wdt(WDT_256S);           //set watch-dog timer
        sleep();
        delay_cycles(10);
        while (i<4)                    //total initialization is ~ 17.06 minutes
        { 
            a2dval = filter_a2d(3);
            restart_wdt();
            delay_ms(600);
            output_high(LED);
            set_pwm1_duty(0);
            printf("\ninitial:  %lu: %4Lu\n\r",i,a2dval);
            i++;
            sleep();
            delay_cycles(10);
        }
        // Record 0ppm value into memory and set initialization flag:
        EEPROM_START_ADDRESS = INIT_DONE_FLAG_ADDR;
        write_eeprom(EEPROM_START_ADDRESS,INIT_DONE);
        write_eeprom(EEPROM_START_ADDRESS+1,(a2dval & 0xFF00)>>8);
        write_eeprom(EEPROM_START_ADDRESS+2,(a2dval & 0x00FF));
        printf("\nLOWLEVELr:   %4Lu\n\r",a2dval);
        a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1)) <<8;     //upper 2 bytes
        a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
        printf("\nLOWLEVELe: %4Lu\n\r",a2dval);

    }
    else
    {
        a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1)) <<8;     //upper 2 bytes
        a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
        printf("\nLOWLEVELe: %4Lu\n\r",a2dval);
        i = 0;
        set_pwm1_duty(0);              //turn off alarm
        setup_wdt(WDT_64S);            //set watch-dog timer minutes
        sleep();
        delay_cycles(10);
        while (i<4)                    //total initialization is ~5.33 minutes
        { 
            a2dval = filter_a2d(3);
            delay_ms(600);
            output_high(LED);
            set_pwm1_duty(0);
            printf("\n%lu: %4Lu\n\r",i,a2dval);
            i++;
            sleep();
            delay_cycles(10);
        }
       
    }
    a2dval = read_eeprom((INIT_DONE_FLAG_ADDR+1)) <<8;     //upper 2 bytes
    a2dval += read_eeprom((INIT_DONE_FLAG_ADDR+2));        //lower 2 bytes
    return a2dval;   // return base value from initial zeroing stored in memory
}

unsigned int16 filter_a2d(unsigned char channel)
{
   int i;                         
   unsigned int16 min= 2000;  // min value is set far out of range of adc
   unsigned int16 max= 0;
   unsigned int16 avg = 0;
   unsigned int16 val = 0;
   
   restart_wdt();
   set_adc_channel(channel);
   delay_us(20);
   for (i=1; i<=7; ++i)
   {
       restart_wdt();
       enable_interrupts(PERIPH);
       read_ADC(ADC_START_ONLY);
       sleep();           //Sleep until A-D conversion is done per errata
       delay_cycles(1);
       printf("RESTART CAUSE: %x", restart_cause());
       val = read_ADC(ADC_READ_ONLY);
       restart_wdt();
       delay_us(20);
       max = (val>=max)?val:max;
       min = (val<min)?val:min;
       avg += val;
   }
   avg = ((avg - max) - min);
   delay_us(20);
   return(avg/5);
}


So the initial restart cause is 3C (normal power up)

then after my warmup, when I should be doing a2d conversions, i have added another printf of restart_cause...

I get zero's for my readings now and the cause prints out (about 30 times) "3F", which is not in the list in the device .h file.

any ideas?
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Jul 14, 2011 8:47 am     Reply with quote

Restart_cause, is _only_ valid for a few lines as the chip boots. As soon as you change any one of a number of settings (things like watchdog for example), the value is not valid any more.
If you want to print restart_cause later in the program, you must save the value as one of the very first few lines of your code, and use this.
Get rid of the later prints of this, they mean _nothing_.

Also, switch to the C standard, and always initialise variables at the start of code sections:
Code:

//Invalid syntax.
void main ()
{   
   
    printf("RESTART CAUSE: %x", restart_cause());
    int i = 0;


///////////////////////

//valid syntax
void main ()
{   
    int i=0;
    printf("RESTART CAUSE: %x", restart_cause());



The point is, it returns '3C' when you first boot (correct), but what does it return when you get the 'periodic resets'?. If it is giving 3C, it means the chip _is_ resetting - electrical noise 99% most likely cause.

PCMprogrammers question was 'find out what the PIC reports as the reason for the reset'.

Best Wishes
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

RESTART CAUSE
PostPosted: Thu Jul 14, 2011 9:19 am     Reply with quote

Ahh i see now..

i have not read up on restart_cause and have never previous used it... this is a big help...

and makes alot of sense.


I will change it all back and try to chance it down more.

I still dont understand why I get only zeros for my ADC readings now... they should be in the 300s - 400's from past experience with this same exact sensor (taken over the past couple of days).
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Thu Jul 14, 2011 9:55 am     Reply with quote

The delay bodge, requires you to read the ADC just _before_ it completes the conversion. This can't be used with the internal ADC clock, since the conversion time is indeterminate.
For the 'sleep' bodge, you'd need:
Code:

//All the ADC setups

disable_interrupts(GLOBAL); //must be disabled or a handler will be called
//disable _all_ other interrupt sources
enable_interrupts (INT_AD);
clear_interrupts(INT_AD); //Clear as last instruction before sleep
read_adc(ADC_START_ONLY);
sleep();
delay_cycles(1);
val=read_adc(ADC_READ_ONLY);


Problems currently, you seem to enable another interrupt (PERIPH), _all_ other interrupts _must_ be disabled, or these can prematurely wake the chip, and the global interrupt flag _must_ be disabled, or an interrupt handler is needed.

Best Wsihes
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

hangup
PostPosted: Thu Jul 14, 2011 11:18 am     Reply with quote

not sure why, but when i use your code above, exactly as typed (except for the term clear_interrupts = clear_interrupt) it just freezes and never returns from sleep (i am assuming).

I never get a display.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 14, 2011 2:17 pm     Reply with quote

A quick way to find out if the watchdog timer is causing the PIC to reset,
is to disable it. Change the fuse to NOWDT and comment out all lines
of code that turn on the watchdog. See if the problem goes away.
deperkin



Joined: 04 Feb 2009
Posts: 83
Location: PA

View user's profile Send private message Send e-mail

restart cause
PostPosted: Thu Jul 14, 2011 2:18 pm     Reply with quote

I have been able to successfully get the restart cause 3 times over the last 45 min or so...

it is 0x1F => Watchdog timeout which does make me think it is the ADC conversion...

For this I have been using the manual A/D technique to get the values.

Trying to read the A/D during sleep has not successfully worked for me yet (not sure why using the above code to disable globals and enable INT_AD causes it to never wake up ... not even once ).


If I cannot get this to work I may be able to directly transistion to a 12f675.... it has some eeprom and I believe would be more reliable...

I unfortunately already made the PCB's for this before I had even seen a reset issue. I did leave a small proto area however.

any thoughts?

Thanks again btw, you are always very helpful
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

Re: hangup
PostPosted: Thu Jul 14, 2011 2:35 pm     Reply with quote

deperkin wrote:
not sure why, but when i use your code above, exactly as typed (except for the term clear_interrupts = clear_interrupt) it just freezes and never returns from sleep (i am assuming).

I never get a display.


Er. That would imply the interrupt was never firing.
You have got ADC_CLOCK_INTERNAL selected?. It'd do that if you had any other clock selected, since then the ADC clock would stop when you went to sleep.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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