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 with turn on Issues with pic 12f506

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



Joined: 24 Jan 2012
Posts: 3
Location: FL

View user's profile Send private message

Help with turn on Issues with pic 12f506
PostPosted: Tue Jan 24, 2012 8:14 pm     Reply with quote

I have a project with the Pic 12F506 where I have three switch inputs and 8 outputs to 2 RGB LEDs (6 total), 1 White LED and 1 IR LED.
Inputs are in port B bits 5, 4 and 3, b0 is not used, b1 controls the IR and b2 controls the white LED, port c controls the RGBs. LEDs are not directly connected to the Pic they are switch by mosfets. with a 20K resistor GD

The program reads the switches. Pin B5 controls whether you have a IR or a Visible mode, and B4 and B3 control functions within the mode, white, green or any other.

The mode switch is usually set to 1 which means IR mode, before the PIC is even on.
But when I just turn on the IC there is a small blink of the white and RGB LEDs, that's not a problem if the mode is set to visual, but if is set to IR is a big issue, that blink is causing all sort of issues. There are two sensors, one for visual spectrum and other for IR, they are next to each other and I don't have access to them to be modified or do anything.


I have done some debounce routines to the initial read of the switch but no luck.

Its odd because if the unit goes off in the IR mode, the next time I turned it on there is no visible blink, but if the unit was off in the visual mode and then the mode switch is set to IR, when the pic is turned on I have the blink. It goes to IR almost immediately but still I have the visual blink which is not acceptable in the IR mode.


\any help will be very appreciated
_________________
The only thing i know is that i know nothing.
temtronic



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

View user's profile Send private message

PostPosted: Tue Jan 24, 2012 8:52 pm     Reply with quote

You'll have to show us your code along with the compiler version. A schematic would be nice.

some questions though...

? Do you have the correct value for the current limiting resistors ?

? Are the 'control ' switches pushbuttons? IF so what is the pullup/down value ? Any electronic debouncing or just software.

? proper value for _mclr pullup?

? proper value for xtal caps?

? power supply ? +5 with at lead 5x max current draw ?
EECA



Joined: 24 Jan 2012
Posts: 3
Location: FL

View user's profile Send private message

PostPosted: Wed Jan 25, 2012 4:54 pm     Reply with quote

Temtronic,

Thanks a lot for your answer the code is below, this is version from which i have detected first the issues, is was compiled with:
CCS PCB C Compiler, Version 4.073, 16875, 25-Jan-12 17:23

and regarding your questions see below in Bold the answers:

? Do you have the correct value for the current limiting resistors ?

The LEDs are not driven by the pic they are connected to the Power Source then to a resistor and then a Mosfet to ground. the pic is connected to the gate of the mosfet and to a 20K resistor that goes to ground

? Are the 'control ' switches pushbuttons? IF so what is the pullup/down value ? Any electronic debouncing or just software.

No pushbuttons they are Normally Open reed switches, and you have VDD,a 200K Resistor, and the reed and ground, i'm taking the signal to the pic form the reed.
No electronic debouncing, i need it to be just software, at this moment i'm not allow to change hardware.


? proper value for _mclr pullup?

NOMCLR
Only reset when power is off


? proper value for xtal caps?

Running from the internal clock, not room in the PCB for XTAl and i only ended up with one pin not used

? power supply ? +5 with at lead 5x max current draw ?

I'm driving the circuit with a 4 amp 5V power source and my current is at the worst 250mA.

the problem shows when i'm switching from one state to another
but mostly when i just turn on the unit even though the switch of the IR is set to be on ir. it takes a blink and then is OK.

Anyway attached is the code, if you could take a look i'll appreciated.

Code:
#include <16F506.h>
#use delay(clock=4000000)
#fuses NOMCLR,NOPROTECT,NOWDT,INTRC_IO,IOSC4

#define SW1_IN1              PIN_B5
#define SW2_IN1              PIN_B4
#define SW3_IN1              PIN_B3

#define WHT_OUT               PIN_B1
#define IR_OUT            PIN_B2
#define GRN1_OUT          PIN_C0
#define RED1_OUT          PIN_C1
#define BLU1_OUT          PIN_C2
#define GRN2_OUT          PIN_C5
#define RED2_OUT          PIN_C4
#define BLU2_OUT          PIN_C3


void output_low(void)          // Turn off all LEDS
{   
   output_low(WHT_OUT);
    output_low(IR_OUT);
    output_low(RED1_OUT);
    output_low(GRN1_OUT);
    output_low(BLU1_OUT);
    output_low(RED2_OUT);
    output_low(GRN2_OUT);
    output_low(BLU2_OUT);
}

void main(void)
{
//Variables Definitions
   unsigned int8 i;
   int1 SW1_IN;
   int1 SW2_IN;
   int1 SW3_IN;
      
//initialization
   
   //ADC set Up
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);
   //set_adc_channel(0);
   
   // Ports set up
     //  setup_vref(false);
   setup_comparator(NC_NC_NC_NC);
   setup_counters(RTCC_INTERNAL,DISABLE_PULLUPS | DISABLE_WAKEUP_ON_CHANGE);

   SW1_IN=input(SW1_IN1);
   SW2_IN=input(SW2_IN1);
   SW3_IN=input(SW3_IN1);
while(TRUE)
{         
         delay_ms(3);
         SW1_IN=input(SW1_IN1);
         SW2_IN=input(SW2_IN1);
         SW3_IN=input(SW3_IN1);
   
   if(SW3_IN==1) // Does the Process below for SW1_IN = High (switch is on Mode A Up)(no visual output only IR)
     {
    output_low(WHT_OUT);    //this was place here to reinforce a no white light
         if(SW1_IN==1) // Does the Process below for SW1_IN = High (switch is on function 1 or 2)     
             {   
            output_low(WHT_OUT);
                  if (SW2_IN==1)// Does the Process below for SW2_IN = High (switch is on function 2)
                     {
                  output_low(WHT_OUT);
                     for(i=0;i<25;i++)    // this for is for the section of time the IR will be on   
                           { 
                             output_high(IR_OUT); // turn on the IR LED for the time set as on
                           delay_ms(8);
                           output_low(IR_OUT); // turn off the LEDs
                             delay_ms(2);       
                             }
                                    output_low(IR_OUT); // turn off the LEDs
                             delay_ms(500);
                  }       
               else // Does the Process below for SW2_IN = High (switch is on Function 1)
                     {     
                  output_low(WHT_OUT);   
                     for(i=0;i<25;i++)    // this for is for the section of time the IR will be on   
                           { 
                             output_high(IR_OUT); // turn on the IR LED for the time set as on
                           delay_us(50);
                           output_low(IR_OUT); // turn off the LEDs
                             delay_us(9950);       
                             }
                                    output_low(IR_OUT); // turn off the LEDs
                             delay_ms(500);
                  }
             }
          else  // Does the Process below for SW1_IN = Low (switch is on function  0)
            {
            output_low();
              }
      }   
   
   else  // Does the Process below for SW3_IN = Low (switch is on Mode B Down)(visual ouput)
   {
   
            if(SW1_IN==1) // Does the Process below for SW1_IN = High (switch is on function 1 or 2)     
             {   
               
               if (SW2_IN==1)// Does the Process below for SW2_IN = High (switch is on function 2)
                     {
                  
                  for(i=0;i<5;i++)    // this for is for the section of time the WHT and GRN will be on   
                           { 
                             output_high(WHT_OUT); // turn on the LED for the time set as on
                           output_high(GRN1_OUT);
                           output_high(GRN2_OUT);
                           delay_us(300);
                           output_high(WHT_OUT); // turn off the LEDs
                             output_low(GRN1_OUT);
                           output_low(GRN2_OUT);
                           delay_us(9700);       
                             }
                  for(i=0;i<20;i++)    // this for is for the section of time the GRN will be on   
                           { 
                             output_low(WHT_OUT); // turn on the LED for the time set as on
                           output_high(GRN1_OUT);
                           output_high(GRN2_OUT);
                           delay_us(300);
                           output_low(WHT_OUT); // turn off the LEDs
                             output_low(GRN1_OUT);
                           output_low(GRN2_OUT);
                           delay_us(9700);       
                             }
                         for(i=0;i<75;i++)       // this for is for the section of time the LED's will be off
                           { 
                             output_low(WHT_OUT);  // turn off the LED for the time set as on
                           output_high(GRN1_OUT);
                           output_high(GRN2_OUT);
                           delay_us(300);
                           output_low(WHT_OUT);   // turn off the LEDs
                           output_low(GRN1_OUT);
                           output_low(GRN2_OUT);
                           delay_us(9700);      
                             }
                   }       
               else // Does the Process below for SW2_IN = High (switch is on Function 1)
                     {
                  output_low(WHT_OUT);     
                  output_high(GRN1_OUT);  // turn off the LED for the time set as on
                  output_high(GRN2_OUT);
                  delay_us(300);
                  output_low(GRN1_OUT);   // turn off the LEDs
                  output_low(GRN2_OUT);
                  delay_us(9700);
                  }
             }
          else  // Does the Process below for SW1_IN = Low (switch is on function  0)
            {
            output_low();
              }
           }   
         
}// Close While
}// Close Main

Thanks again
_________________
The only thing i know is that i know nothing.
EECA



Joined: 24 Jan 2012
Posts: 3
Location: FL

View user's profile Send private message

Latest Revision of code, still issues there
PostPosted: Fri Jan 27, 2012 1:19 pm     Reply with quote

This is the latest code version. I changed to a switch/case, in "case" I was missing any interim state while the switch are moving from one place to another.

I also include the debounce routines. Any help will be appreciated. I don't understand why the visual LED are turning on during switch transitions. The effect is worse at start, but happens also during on condition when changing sw2.
I must be missing something here!!!
Code:

#include <16F506.h>
#use delay(clock=4000000)
#fuses NOMCLR,NOPROTECT,NOWDT,INTRC_IO,IOSC4
//#use standard_io(B)


#define SW1_IN1              PIN_B5
#define SW2_IN1              PIN_B4
#define SW3_IN1              PIN_B3

#define WHT_OUT               PIN_B1
#define IR_OUT            PIN_B2
#define GRN1_OUT          PIN_C0
#define RED1_OUT          PIN_C1
#define BLU1_OUT          PIN_C2
#define GRN2_OUT          PIN_C5
#define RED2_OUT          PIN_C4
#define BLU2_OUT          PIN_C3

void outputlow(void)
{
unsigned int8 portB;
unsigned int8 portC;   
portB=0b00000000;
portC=0b00000000;
output_b(portB);
output_c(portC);
}

void Output_IR(void)
{
unsigned int8 portB;
unsigned int8 portC;   
portB=0b00000100;
portC=0b00000000;
output_b(portB);
output_c(portC);
}


void Output_GRN(void)
{
unsigned int8 portB;
unsigned int8 portC;   
portB=0b00000000;
portC=0b00100001;
output_b(portB);
output_c(portC);
}


void Output_WHT_GRN(void)
{
unsigned int8 portB;
unsigned int8 portC;   
portB=0b00000010;
portC=0b00100001;
output_b(portB);
output_c(portC);
}


int1 debounce_sw1(void)
{   
   unsigned int8 i;
   int1 temp;
   temp = 0;
   temp = input(SW1_IN1);
   
   for (i=0;i<25;i++)
   {   
      delay_ms(1);
      if (temp==input(SW1_IN1))
         {
         temp=input(SW1_IN1);
         }
      else
         {
         i=0;
         temp=input(SW1_IN1);
         }
      
   }
return (temp);
}

int1 debounce_sw2(void)
{   
   unsigned int8 i;
   int1 temp;
   temp = 0;
   temp = input(SW2_IN1);
   
   for (i=0;i<5;i++)
   {   
      delay_ms(1);
      if (temp==input(SW2_IN1))
         {
         temp=input(SW2_IN1);
         }
      else
         {
         i=0;
         temp=input(SW2_IN1);
         }
      
   }
return (temp);
}

int1 debounce_sw3(void)
{   
   unsigned int8 i;
   int1 temp;
   temp = 0;
   temp = input(SW3_IN1);
   
   for (i=0;i<5;i++)
   {   
      delay_ms(1);
      if (temp==input(SW3_IN1))
         {
         temp=input(SW3_IN1);
         }
      else
         {
         i=0;
         temp=input(SW3_IN1);
         }
      
   }
return (temp);
}
void main(void)
{
   
   //Variables Definitions
   unsigned int8 i;
   unsigned char switches;
   int1 SW1_IN;
   int1 SW2_IN;
   int1 SW3_IN;

   //initialization

//set_tris_b(0x07);      //0000 0111     seting port_B  as outputs
//set_tris_c(0x3f);      //0011 1111     seting port_C as outputs   


   //ADC set Up
   setup_adc_ports(NO_ANALOGS);   
   setup_adc(ADC_OFF);
   //set_adc_channel(0);
   
   // Ports set up
     //  setup_vref(false);
   setup_comparator(NC_NC_NC_NC);
   setup_counters(RTCC_INTERNAL,DISABLE_PULLUPS | DISABLE_WAKEUP_ON_CHANGE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_64);

   outputlow();      
   delay_ms(20);
   SW3_IN = debounce_sw3();
   SW2_IN = debounce_sw2();
   SW1_IN = debounce_sw1();
   switches = 0;
   outputlow();
while(TRUE)
{   
  switches = 0;
  switches |= SW3_IN << 0;
  switches |= SW2_IN << 1;
  switches |= SW1_IN << 2;
   switch(switches)
     {
      case 0b00000100:
       for(i=0;i<25;i++)    // this for is for the section of time the GRN will be on   
         { 
         Output_GRN();
         delay_us(300);
         outputlow();
         delay_ms(97/10);
         }
         SW3_IN = debounce_sw3();
         SW2_IN = debounce_sw2();
         SW1_IN = debounce_sw1();
      
      break;
      case 0b00000101:
             for(i=0;i<25;i++)    // this for is for the section of time the IR will be on   
            { 
            Output_IR();
            delay_us(50);      //output_high(IR_OUT); // turn on the IR LED for the time set as on
            outputlow();
            delay_ms(199/20);      //output_low(IR_OUT); // turn off the LEDs
            }
            outputlow();
         delay_ms(500);
         SW3_IN = debounce_sw3();
         SW2_IN = debounce_sw2();
         SW1_IN = debounce_sw1();
      break;
      case 0b00000110:
         for(i=0;i<5;i++)    // this for is for the section of time the WHT and GRN will be on   
            {
            Output_WHT_GRN();
            delay_us(300);
            outputlow();
            delay_ms(97/10);       
               }
         for(i=0;i<20;i++)    // this for is for the section of time the WHT and GRN will be on   
             { 
               Output_GRN();
            delay_us(300);
            outputlow();
            delay_ms(97/10);       
               }
              for(i=0;i<75;i++)       // this for is for the section of time the LED's will be off
            { 
              Output_GRN();
            delay_us(300);
            outputlow();
            delay_ms(97/10);      
               }
         SW3_IN = debounce_sw3();
         SW2_IN = debounce_sw2();
         SW1_IN = debounce_sw1();
      break;
      case 0b00000111:
         for(i=0;i<25;i++)    // this for is for the section of time the IR will be on   
            { 
            Output_IR(); // turn on the IR LED for the time set as on
            delay_ms(8);
            outputlow(); // turn off the LEDs
            delay_ms(2);       
            }
                outputlow();
            delay_ms(500);            //output_low(IR_OUT); // turn off the LEDs
         SW3_IN = debounce_sw3();
         SW2_IN = debounce_sw2();
         SW1_IN = debounce_sw1();
      break;
      
         default:
         
      SW3_IN = debounce_sw3();
      SW2_IN = debounce_sw2();
      SW1_IN = debounce_sw1();
      outputlow();
        break;
     }          
}// Close While
}// Close Main

_________________
The only thing i know is that i know nothing.
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