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 support@ccsinfo.com

[HELP] PIC18F25K22 run make power supply down.

 
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

[HELP] PIC18F25K22 run make power supply down.
PostPosted: Tue Jul 29, 2014 7:13 pm     Reply with quote

Hi
I'm doing project about driver triac using PIC18F25K22.
In circuit, I used transformerless power supply type to make a 5v power for PIC.
I'm referenced appnotes of Microchip to designed.
I used D1: 12V zener diode, and D3: 5.1V zener diode
But I have a problems when PIC run, the power supply down to 3.3V, if I erase program on PIC, the power up to ~5V again.
In my program,I measure ADC on AN0 channel and driver 2 triacs, and using timer 1 to make a timeout when load on.
Here is my schematic:



And my program:
Code:

   
#include "18F25K22.h"
#fuses NOMCLR, HSM, NOPLLEN,  PUT, NOPROTECT, NOLVP, NOWDT, NOBROWNOUT, NODEBUG, NOPBADEN, NOSTVREN, NOPROTECT, NOCPD, NOWRTB, NOEBTR, NOEBTRB
#device ADC=10
#use delay(clock=10000000)
//!#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, errors) // HARD UART

unsigned int8 temp=0, temp_b=0;
unsigned int16 count=0, count_t0=0, pulse=0;
unsigned int1 full_timer0=0;
unsigned int8 en_timer0=0;

unsigned int1 detect_pulse_big=0, detect_pulse_lit=0;
unsigned int1 big_press=0, lit_press=0;
unsigned int1 full_pulse_big=0, full_pulse_lit=0;
unsigned int16 volt_adc=0;
float volt_disp=0;

//-----------------------------------------------------------------------------
// led: high (ON)
// Triac:   HEAT : high(ON)
//          PUMP:  low(ON)

#define  led_big     PIN_C3
#define  led_lit     PIN_C2
#define  heat_out    PIN_C1
#define  pump_out    PIN_C0
//-------------------------------------------------------------------------------------------------
#int_ext
void ngat_detect_ac(void)
{     

}
//-------------------------------------------------------------------------------------------------
#int_ext1
void ngat_detect_sensor(void)
{
   pulse++;
   if( detect_pulse_lit==1 && pulse>=120)   
   {
      full_pulse_lit=1;
      pulse=0;
      detect_pulse_lit=0;
   }
   
   else if( detect_pulse_big==1 && pulse>=260)
   {
      full_pulse_big=1;
      pulse=0;
      detect_pulse_big=0;
   }
   
   clear_interrupt(int_ext1); 
}

//-------------------------------------------------------------------------------------------------
#int_rb
void ngat_phim()
{
   int current;
   static int last=0;
   current=input_b();
   
   if ((!bit_test(current,4))&&(bit_test(last,4)))
   { 
      big_press =1;
      detect_pulse_big=1;
   }
   if ((!bit_test(current,5))&&(bit_test(last,5)))   
   { 
      lit_press =1;
      detect_pulse_lit=1;
   }
   last=current;
}


//-------------------------------------------------------------------------------------------------
#int_timer0
void ngat_timer0(void)
{
    set_timer0 (247); 
    count_t0++;
    if(count_t0==30)
    {
      full_timer0=1;
    }
    clear_interrupt(int_timer0);

}

void main(void)
{
   delay_ms(1000);
   
   set_tris_a(0x01); // heat_in: RA0
   set_tris_b(0x31); // big: RB4, lit:RB5, sensor_V:RB0
   set_tris_c(0x00);
   set_tris_c(0x00);
   set_tris_e(0);
   
   output_low(heat_out);   // off heat   
   output_high(pump_out);  // off pump   

   
         
   full_pulse_big=0;
   full_pulse_lit=0;
   big_press=0;
   lit_press=0;
   
   temp_b= input_b();

   
   ext_int_edge (0, H_TO_L) ;
   clear_interrupt (int_ext);
   enable_interrupts (int_ext); 
   
   set_timer0(159);  //10ms                         
   setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_256);
   
   setup_adc_ports(sAN0, VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);            // Built-in A/D setup function
   set_adc_channel(0);

   enable_interrupts(int_rb);
   enable_interrupts(int_ext);
   enable_interrupts(global);
   
   output_low(led_lit);   // off leds
   output_low(led_big);     
     

   
   output_high(heat_out);
   output_low(pump_out);
   delay_ms(10000);
   output_low(heat_out);
   output_high(pump_out);
     
   for(;;)
   {
      //---------------------------- detect_key_press----------------------------------
      if( big_press==1 || lit_press==1 )
      {
         //---------------------- Heat on -------------------------------------
         output_high(led_lit);   // offset led
         output_low(led_big);
         
         output_high(heat_out);  // heat on operation
         enable_interrupts(int_timer0);

         //---------------------- Read ADC temperature--------------------------
         loop:
         volt_adc= read_adc();
         delay_ms(1000);                     
         volt_disp= volt_adc*0.0045;
//!         printf("\n\r volt_adc: %4.3f", volt_disp); 
         output_toggle(led_lit);
         output_toggle(led_big);
         while(volt_disp <3.5)
         {
            goto loop;
         }
         
         if( big_press==1)
         {
            output_low(pump_out);
            while( full_pulse_big==0 );
            output_high(pump_out);
         }
         else if( lit_press==1)
         {
            output_low(pump_out);
            while(full_pulse_lit==0);
            output_high(pump_out);
         }
         
         output_low(heat_out);
         output_high(pump_out);
         disable_interrupts(int_timer0);
         big_press=0;
         lit_press=0;
         detect_pulse_big=0;
         detect_pulse_lit=0;
         full_pulse_big=0;
         full_pulse_lit=0;

      }
   }
   
   
}


Pls give me a bugs in this circuit, I don't understand somethings make a errors, I tried cutout 2 triac circuit and it not still better.
Thanks.
_________________
Begin Begin Begin !!!
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jul 30, 2014 2:34 am     Reply with quote

Have you checked:-

1) Current capability of your power supply?
2) Current drain of programmed PIC with a standard 5V DC supply?

Mike

BTW
I found your schematic difficult to read with it being upside down.
It's easier to have positive to top, negative below.
alan



Joined: 12 Nov 2012
Posts: 350
Location: South Africa

View user's profile Send private message

PostPosted: Wed Jul 30, 2014 2:59 am     Reply with quote

In addition to what Mike asked.
What are your load on the pump and heat output as you are also supplying them from your Vcc?

Regards
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 30, 2014 3:40 am     Reply with quote

Great for posting a schematic! Not many people do this and it makes giving support so much easier.

I can see the basic part is the capacitive power supply of AN954 but then some extra refinements are added.
Which Application Note did you get this schematic from? So we can do some reading.

What is your mains voltage? 115 / 230V?
What is your mains frequency? 50 / 60 Hz?
temtronic



Joined: 01 Jul 2010
Posts: 9126
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jul 30, 2014 5:19 am     Reply with quote

Odds are real good the PIC is 'current starved' due to that power supply design.

It's nice to see the schematic though I don't understand WHY you're using it.

The main problem is lack of isolation ! The 'kill factor'. Maybe it's cause I'm getting old , or been 'zapped' once too often, but for just $5 you can buy a regulated 5V 1A power supply 'wallwart' to safely power you project. It is CHEAPER than all those components in your PSU.
Also I use an optotriac(MOC3031) to drive my power triacs. Again it adds isolation which protects the PIC and YOU from being zapped.
I also have an LED in the load side to show that the device is on.

hth
jay
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Jul 30, 2014 6:55 am     Reply with quote

TIME:

you have
#use delay(clock=10000000)

but the schemo says 16mhz crystal
so this
set_timer0 (247);

will NOT produce the calculated delay.

also
clear_interrupt(int_ext1);
may be redundant.

i second the awfulness of the way you get Vcc
and am pretty sure your zero cross detector circuit (HLVD2)will fail
spectacularly if there is any reactance in your "pump" TRiac loads or at least be very unreliable.



Sad Sad
Ttelmah



Joined: 11 Mar 2010
Posts: 19246

View user's profile Send private message

PostPosted: Wed Jul 30, 2014 11:48 am     Reply with quote

As has already been said. Ugh...

There are several really horrible things. I screamed when I saw an ICSP connector on a non isolated circuit. This is potentially lethal, of you, programmer, and PC.

However key thing for it not working is just how much current things draw. Assuming red LED's, each of these could draw about 6mA each. Add the PIC, buttons, and the drives to the TRIAC's, and you are talking perhaps 25mA worst case. You are lucky to even get 3v... The application note is for 16mA _max_ with the values given, and your capacitor is smaller than the one in the note.
tienchuan



Joined: 25 Aug 2009
Posts: 175

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Jul 30, 2014 11:48 pm     Reply with quote

Hi alls, thanks for replies.
@Mike Walne: now, I haven't a digital multimeter to measure current. I'll checked again when i borrowed it.
@ckielstra: Main power supply is 220V/50Hz.Yes, this circuit is redraw follow in one's machine of my friend. The value of components isn't clearly. This machine corrupt after using in along time so that I want make a new PCB to control this machine. ALL block in this circuit are using again, without MCU, which I replaced by PIC18F25K22.
In this circuit, have a zero-cross detect block, HLVD but I don't use in my program.
@temtronic: because the board layout is small so that I can't find a solution to make a power supply simpler than using this type. Because I don't make a PCB to commercial so that I don't a trouble:)
If you have a solution better, pls show me some references:)
@asmboy: sr, i place a 10MHz crystal in my PCB. so that the timer value is true.
@Ttelmah: sr, my photo of schematics i cutout ICSP header. I connected with PIN in PIC. As you told above, non isolated meaning?Smile
3V when pic start run and can down power supply make me lest I'll calculated ADC value is wrong, so that my problem is make a power supply is 5v stable, before continuing :D
Thanks all, Have a nice day Smile
_________________
Begin Begin Begin !!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19246

View user's profile Send private message

PostPosted: Thu Jul 31, 2014 1:14 am     Reply with quote

'Non isolated', because that is the nature of this supply. Large parts of the system are potentially connected directly to the incoming supply.

You need to understand, that this type of supply is potentially _lethal_. Though cheaper (very slightly), than a transformer based supply, it brings big costs with it. For instance, with a transformer based supply, your 'buttons' can be simple calculator type buttons, and the system can be safe, and legal. However with the non isolated supply, the buttons will have to meet much higher insulation requirements, and will cost more than the simple buttons. Similarly the actual capacitor used, must be X2 certified (this guarantees it's 'failure' mode).
Now the point about the ICSP connector, is that with this type of supply, this is connected directly to the circuitry, that is connected to the mains. As such, a really easy way of killing yourself. If this is a commercial product, this will need to be covered, with a cover that is not easy to remove (preferably requiring special tools), and is marked for safety. The exact regulations will depend on your country.
All of the circuitry will need to be in an insulated casing, that again meets the local regulations for 'live' circuitry.

You need to understand the actual costs (both in financial terms, and safety terms), of using this type of supply, before thinking about using this in a design. Doing a basic electrical safety training course, before starting.

Such supplies make sense, when trying to save a few pence/cents, in a system which is made in the tens of thousands, and is already going to be fully insulated because of the other parts involved. However for anything involving smaller quantities, it is usually easier to meet safety requirements using a properly isolated supply....

As drawn there are other problems, for instance, there needs to be a fuse between the external connection pin, and the Tranzorb, on the board, or there is no actual 'safety' added by this component. As drawn, I found myself 'going back' to safety shows put on by some electrical licensing authorities, displaying products that they have found, as examples of 'how not to do it'....
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