PDA

View Full Version : wierd problem with 12f629 Need Help Despretly



Nadeem
- 15th June 2005, 20:30
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--;
}
}

Darrel Taylor
- 15th June 2005, 20:59
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