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

chip reset timing problems

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



Joined: 29 Dec 2009
Posts: 3

View user's profile Send private message

chip reset timing problems
PostPosted: Tue Dec 29, 2009 10:06 am     Reply with quote

Hello all, I have a very simple test program written for a 16f877:
Code:

#include <16F877.h>
#device ICD=TRUE
#device *=16
#use delay(clock=20000000)

#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use spi(DI=PIN_C5, DO=PIN_C4, CLK=PIN_C3)

float loalarm = 0;

void print_string(char string[])
{ ... }

void run_setup()
{
  setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  setup_timer_1(T1_DISABLED);
  setup_timer_2(T2_DISABLED,0,1);
  setup_spi(SPI_MASTER|SPI_MODE_0| SPI_CLK_DIV_16);

  output_high(PIN_B4); 
  delay_ms(10);

  if (read_eeprom(0) == 0xFF)
    loalarm = 0;
  else
    loalarm = read_float_from_eeprom(0);
}


void main()                               
{
  char foo[5]={"1010"}
  run_setup();

  while(TRUE)
      print_string(foo);
}

Nothing too fancy. The read_float_from_eeprom function was taken from here http://www.ccsinfo.com/forum/viewtopic.php?t=32722&start=1

The code works properly until I start to reset the power, and I'm not even resetting it fast. When it powers on, my led display that normally prints 1010 now prints garbage. I need a way to delay the chip from running until the oscillator and the power supply have settled but I haven't been able to figure it out. I tried using setup_oscillator(), but the compiler didn't recognize it. Much thanks in advance!!!
Ttelmah
Guest







PostPosted: Tue Dec 29, 2009 11:22 am     Reply with quote

How is MCLR generated on the chip?. What time constant is involved in this?. What reservoir capacitance is present on the supply?. What loads are present?. How is the ICD powered?.
Have you tried enabling 'brownout'?.
I'd suspect that what is happening, is that your supply is dropping reasonably quickly, into the 'brownout' region, and is then dropping much more slowly, as some circuitry switches off. When you re-apply the supply, sections of the circuitry (possibly including the PIC), have not actually reset.
As far as the PIC is concerned, this is what 'BROWNOUT' is for. So the first thing is to try enabling this.
There is a separate 'issue', that some ICD setups, can supply sufficient power, that they prevent the circuitry fully switching off. Does the same thing happen without ICD?.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 29, 2009 1:45 pm     Reply with quote

Quote:
#include <16F877.h>
#device ICD=TRUE
#device *=16
#use delay(clock=20000000)

#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,NOBROWNOUT
#use spi(DI=PIN_C5, DO=PIN_C4, CLK=PIN_C3)

void run_setup()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_spi(SPI_MASTER|SPI_MODE_0| SPI_CLK_DIV_16);

Also, here you are trying to mix the two methods of setting up the SPI.
Don't do that. My advice is to use the setup_spi() method. It's easier
and less buggy. Then you can use spi_write() and spi_read() to
do SPI operations. There are many examples in the forum archives
of using this method to talk to SPI slave chips with the PIC.
ccole



Joined: 29 Dec 2009
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 30, 2009 12:11 pm     Reply with quote

Thanks for the replies guys. It looks like when I power cycle quickly, it latches on to the last output on the led display and then the processor doesn't execute anymore instructions....after reading the pic datasheet, it looks like it is powering up in "sleep" mode. Is there any way I can keep it from sleeping? I read some code examples (and tried some) to try to enable an interrupt to wake up the processor (off of timer0) from sleeping on a power up, but nothing seems to work... I'm somewhat stumped again, anybody have experience with processors powering on in sleep mode?
ccole



Joined: 29 Dec 2009
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 30, 2009 12:15 pm     Reply with quote

also, somewhat confused about the "INT_EXT" interrupts...what can trigger those?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 30, 2009 12:18 pm     Reply with quote

They don't power-up in sleep mode. If your oscillator circuit is incorrect,
the oscillator might not be running. Or, if you let the program run off
the end of main, then it will go to sleep. Or, if you run the PIC at 3.3v
and enable the Brownout fuse (on the 16F877), then the PIC will be
held in reset permanently.

Try a simple test program to blink an LED on pin B0:
Code:

#include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

//===================================
void main()


while(1)
  {
   output_high(PIN_B0);   // Blink LED on pin B0
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }


 
 
 
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