wierd problem with 12f629 Need Help Despretly


Closed Thread
Results 1 to 2 of 2
  1. #1
    Nadeem's Avatar
    Nadeem Guest

    Default wierd problem with 12f629 Need Help Despretly

    Hi Every one. I realy need help urgently i hope some one ans Fast.I think i am doing somthing wrong with initializing my chip , but cant figure out what.

    K We have a power supply circuit and we are using the 12f629 Pic to control it.
    we are using .

    GP0 for input to detect if hi or low
    GP1 for output to drive a mosfet wich turns on/off 12v source
    GP2 for output to drive a mosfet wich turns on/off 19v source
    GP3 for nothing
    GP4 for output to drive a Relay wich turns on/off for 600ms
    GP5 for input to read to determin if system is still on or offf

    The wierd thing is the enitre code works perctly except one part of it causes the entire chip to crash and not work at all

    Basicaly we want the pic to control when to turn on/off the supplies.It is going to be pluged into a rugged computer.The power supply will be used in cars. It is suppose to detect the ignition (gp0). If ignition is on it will first turn on the 12v source(GP1) then the 19v source(gp2) then will flick the relay for 600ms to turn the computer of . The chip will always monitor the Ignition(gp0). When turned of it will cary out the the shut down seq wich is flicking the relay again for 600ms, waiting some time for the system to shutdown then turning of the 12V source. NOT THE 19V source. But if the computer is still determined to be on after the shutdown sequence started we wana cut the main power (19v) to the system in order to recover from a system crash. This is the time when the the entire chip simply just crashes and all pins go low. I have to cut the power to the chip in order to make it work again.


    Heres the code I hope u all can ans I will realy apreciat it.

    /*Programmer: Nadeem Jamal & Mill Chaudhry */
    /*Date: January 30, 2004 */
    /*FileName: startuptiming.c */
    /*Description: Gives HI on GP1 after reading HI on GP0 then */
    /* gives HI on GP2 for 400ms only. Also after */
    /* detecting LO on GP0,gives HI on GP2 for 400ms*/
    /* only and then LO on GP1.SYSTEM IS OFF NOW */

    #include <12F629.h>
    #fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOCPD,NO MCLR
    #use delay(clock = 4000000)
    #use fast_io(A)


    #define shutdwn_delay_min 1 //turn CPU off this much time after the ignition goes off
    #define COMPARATOR 0x19 //Address of comparator register in the PIC
    #define TurnCPU_on_after 4000 //4000ms or 4 sec
    #define switch_on_delay 600 //600ms or .6 sec
    #define switch_off_delay 600 //600ms or .6 sec
    #define MainPower_off_delay 45 //5 min for main power to turn off
    #define CMDSHUT 0
    #define CMDON 1
    #define STATUS 0x03
    #define GPIO 0x05
    #define CMCON 0x19
    #define ANSEL 0x9f
    #define TRISIO 0x85
    #define RP0 0x20

    void checkturnoff(int8 turnoffdelay); //function that gives delay before shutdown
    void ToggleCPU_PushButton(int8 Command);

    //*********************MAIN code starts here**********************//
    void main()
    {
    int8 turnoffdelay = shutdwn_delay_min; //shutdown delay variable
    int8 MainPower_off;
    int1 pinstatus; //stores the GP0 status
    int1 toggle;
    //set_tris_A(0x29); //Makes GP0 and GP3 as input and rest as outputs
    output_A(0x00);


    //Disabling the comparator to use A0 as digital input
    #ASM
    //movlw 0x07
    //movwf COMPARATOR f
    clrf GPIO ;Init GPIO
    movlw 0x07 ;Set GP<2:0> to
    movwf CMCON ;digital IO
    clrf ANSEL ;Digital I/O
    movlw 0x09 ;Set GP<3:0> as inputs
    movwf TRISIO ;and set GP<5:4,1:0>
    ;as outputs
    #ENDASM


    output_high(PIN_A2);
    output_high(PIN_A1);
    while(TRUE) //make the PIC run always
    {

    //turns PSupply on

    while(!INPUT(PIN_A0)); //reads for GP7, if ignition on or off, if off stays here
    delay_ms(200);
    while(!INPUT(PIN_A0));

    delay_ms(1000);
    output_low(PIN_A1); //turns main board on

    delay_ms(TurnCPU_on_after);
    ToggleCPU_PushButton(CMDON);
    checkturnoff(turnoffdelay); //goes in this function until ignition turns off and then waits for 5min
    toggle = 1;
    MainPower_off = MainPower_off_delay;
    while(toggle)
    {
    pinstatus = INPUT(PIN_A0);
    switch (pinstatus)
    {
    case 1:
    checkturnoff(turnoffdelay);
    break;
    case 0:
    ToggleCPU_PushButton(CMDSHUT);
    while(MainPower_off)
    {
    delay_ms(1000);
    MainPower_off--;
    }

    if (INPUT(PIN_A5))
    {
    output_low(PIN_A2);
    }

    delay_ms(1000);

    output_high(PIN_A1);
    output_high(PIN_A2);

    toggle = False;

    break;
    }
    }
    }
    }



    void ToggleCPU_PushButton(int8 Command)
    {
    if(Command==CMDON && !INPUT(PIN_A5))
    {
    output_high(PIN_A4); //turns the switch on
    delay_ms(switch_on_delay);
    output_low(PIN_A4); //turns the switch back off
    }
    if(Command==CMDSHUT && INPUT(PIN_A5))
    {
    output_high(PIN_A4); //turns the switch on/
    delay_ms(switch_on_delay);
    output_low(PIN_A4); //turns the switch back off

    }
    }

    void checkturnoff(int8 turnoffdelay)
    {
    while(INPUT(PIN_A0));
    while(turnoffdelay)
    {
    delay_ms(60000);
    turnoffdelay--;
    }
    }

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Nadeem,

    Your code is written for a C compiler.

    These forums are dedicated to PicBasic and PicBasic Pro from meLabs. You may want to try somewhere else.

    Some people here may be able to help out, but it will probably be awhile before you get a response, and you seem to be in a hurry.

    Best regards,
    Darrel

Similar Threads

  1. Problem with 12F629, servo and EEPROM
    By Atom058 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 1st March 2008, 09:53
  2. Weird problem with 12F629
    By martarse in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th May 2005, 07:15
  3. Another 12F629 Rookie problem
    By BGreen in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd November 2004, 07:25
  4. Very wierd problem
    By jswayze in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th November 2004, 04:56
  5. Problem Pic 12f629
    By diegover in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 19th July 2004, 11:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts