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

Problem when using both HLVD interrupts and Brownout Func
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Mar 31, 2015 3:28 am     Reply with quote

Thanks for your reply.
I'll find an oscilloscope to test this circuit.
Now, I have find a reason make a problem, when i not using brownout reset, it can save data to EEPROM, but if i disable brownout reset, the PIC will hang up when start.
Or Can I set brownout reset lower than 2.1V ?
Thanks.
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Tue Mar 31, 2015 7:47 am     Reply with quote

That is because the _rise time_ of your supply is too long.

Your PIC requires the supply to _rise_ at at least 0.05V/mSec, or the internal reset circuit won't work.... D004 in the data sheet.

You need to add an external reset circuit Figure 4-2 in the data sheet. This is needed if the power-up slope is too slow. What is happening is that your supply is coming up so slowly that the chip doesn't start, but spends long enough in the brownout region, that enabling the brownout triggers it to reset and start.....

As I said, you have supply problems.....
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Apr 01, 2015 10:32 pm     Reply with quote

Thanks for your reply.
I have tried the reset circuit in datasheet, but I don't find how to calculate value for components.
I chose R=10k, R1=2.2K, C=100pF, D: 1N5819
https://drive.google.com/file/d/0Bz215_lkn4g-cEk2aTlpZXFGUW8/view?usp=sharing
Also, I have change the Schottky diode into 1N5819, so that now the supply power for PIC about 4.8V, but the result no change, the PIC still hang when start after power loss, without using Brownout Reset.
Is it right in my reset circuit?
I'm tried measure this circuit with NI VirtualBench and show the power supply down from 4.8V to 3V about 1s
http://www.ni.com/virtualbench/
https://drive.google.com/open?id=0Bz215_lkn4g-cTVnWFQyQkVSc2s&authuser=0
I'll tried this oscilloscope and give a result.
Thanks you.
_________________
Begin Begin Begin !!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Apr 05, 2015 6:35 pm     Reply with quote

Hi all.
I tried to change the power for VDD of reset pin to VDD for components (seperate VDD with PIC and EEPROM) so that the reset for PIC is fast.
But now I can't save data eeprom within time of power backup from capacitor?
I changed this right in case?
Thanks.
_________________
Begin Begin Begin !!!
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Apr 05, 2015 7:43 pm     Reply with quote

tienchuan wrote:
Hi all.
I tried to change the power for VDD of reset pin to VDD for components (seperate VDD with PIC and EEPROM) so that the reset for PIC is fast.
But now I can't save data eeprom within time of power backup from capacitor?
Thanks.

I changed this right in case?
And it is funny, when i changed frequency from 40MHZ (using crystal 10MHZ, and enable PLL) to 10MHZ (HS) PIC can save data to eeprom, but i want the normal PIC run with 40MHZ, only power loss PIC switch to 10MHZ, can i do it?
Pls show me way to final this project !
Thanks
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Mon Apr 06, 2015 12:41 am     Reply with quote

Not possible.

However what you can do is switch to the internal 8MHz oscillator.

setup_oscillator(OSC_8MHz | OSC_INTRC);

Remember though that if you do this any code from this point that uses software based delays (delay_us for example), will then run at 1/5th the speed expected.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Apr 07, 2015 9:15 pm     Reply with quote

Thanks for your answer.
I have changed this oscillator to 8MHZ when HLVD interrupts occuring.
Also, I added reset_cpu() function after saved processing data to EEPROM, it like as:
Code:

#int_lowvolt
void ngat_hlvd(void)
{     
         HLVD_EN_BIT=0;
         if(save_tag_eepr==1)
         { 
            setup_oscillator(OSC_8MHz | OSC_INTRC);         
            BROWNOUT_EN=0;           
            setup_timer_0(T0_OFF);
            setup_timer_1(T1_DISABLED);
            setup_timer_2(T2_DISABLED,195,16);         
            if(app_code==0)
            {
               app_code= app_code_new;
            }
           
            pt_eepr   = make16(read_ext_eeprom(0), read_ext_eeprom(1) );
           
           
            if(pt_eepr==0) {  pt_eepr=20;}                         
            pt_eepr+=1;                                                                                                                                       
            if(chk_offset_pc_new==1) write_ext_eeprom(pt_eepr, 0xC0);   
            else write_ext_eeprom(pt_eepr, 0x80);
           
                                                                             
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr, make8(count_ac,2));   //delay_us(100);       
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr, make8(count_ac,1));   //delay_us(100);   
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr, make8(count_ac,0));   //delay_us(100); 
           
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr, make8(app_code,2) );   //delay_us(100);
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr, make8(app_code,1) );   //delay_us(100);
            pt_eepr+=1;
            write_ext_eeprom(pt_eepr,make8(app_code,0));     //delay_us(100);   

            write_ext_eeprom(0, make8(pt_eepr,1) );          //delay_us(100);
            write_ext_eeprom(1, make8(pt_eepr,0));          //delay_us(100);

            save_tag_eepr=0;
            BROWNOUT_EN=1;
         } 
         
      leds_on;    // discharge capacitor fast
      reset_cpu();
}

And PIC can save data eeprom and reset fast, is it a good solutions or must check again VDD and allow PIC run continue?
Pls show me a good way in this case !
Thanks.
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 20061

View user's profile Send private message

PostPosted: Wed Apr 08, 2015 2:00 am     Reply with quote

You really should or just simply delay.
Imagine the situation. Power drops low enough that INT_LOWVOLT triggers, but then sits still above the voltage where the PIC actually stops working.
You finish your write, reset, interrupts are not enabled at this point. The chip then tries to start, gets to the point where it enables interrupts, and the lowvolt then triggers again. However the power is already very low, and if it then decides to finish going 'off', and there is not time for the write to complete. Result garbage.
It is the situation where you get power fluctuating, and then finally going off, or coming back on 'fuzzy supply', that you have to deal with.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Thu Apr 09, 2015 7:16 pm     Reply with quote

Thanks for your repply.
In this project, I intended that the power is turnoff suddenly, PIC can save data to EEPROM before run again when power on.
And I have a problems that I can check power stable before allow PIC run in main program. In my program, I only check HLVD and IRVST bit after turn on HLVD interrupt, may be seem isn't relative with power stable.

Define HLVD bits:
Code:

#bit HLVD_EN_BIT  = getenv("SFR:HLVDCON").4                                                                                                                   
#bit IRVST_BIT    = getenv("SFR:HLVDCON").5                                                                                                                       
#bit LVDIF_BIT    = getenv("SFR:PIR2").2   


Check HLVD in main program:
Code:

   setup_low_volt_detect(  LVD_TRIGGER_BELOW| LVD_38);
   while(IRVST_BIT==0);
   wait_vdd_stable();   
   delay_ms(100);
   enable_interrupts (int_lowvolt);

Is there a way to check power stable when turn on right?
Thanks & Regards!
_________________
Begin Begin Begin !!!
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 Previous  1, 2
Page 2 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