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

Help For Serial communication & Phase Angle Control

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



Joined: 05 Jun 2013
Posts: 10
Location: Mumbai

View user's profile Send private message Send e-mail

Help For Serial communication & Phase Angle Control
PostPosted: Fri Jun 28, 2013 1:49 am     Reply with quote

I want to communicating with two PIC 16F873A with RS485. Master containing keys & Slave Contain Zero detect & Phase Control. I have written program from Master as if key1 press it send data if key 1 pressed contionuosly upto 5 Sec then data changes from 170 to 240. & if key2 pressed contionuosly upto 5 Sec then data changes from 240 to 170. and data send from master after each count value changes. and on Reciever Side It Recieve data and after Zero cross detect generate phase angle delay (put recieve value on TIMER 0 t )to give Pulse to MOC3023. But I had checked it cant control. I Cant, understand where is problem can any guide me.

my Code as
Code:

//SLAVE CODE

#include <rs485.c>
#include <stdlib.h>

#use rs232(xmit=PIN_C6,rcv=PIN_C7,enable=PIN_B0,baud=9600)

#define MINIMUM_FIRING_ENGLE   170
#define MAXIMUM_FIRING_ENGLE   230

#byte PortB = getenv("SFR:PortB")

void initialize_ports(void);
void initialize_variables(void);

unsigned int8 fire_on_delay;
unsigned int8 firing_angle;
unsigned int1 TRAIC_GATE;

 int8 count;
 
//------------------------------------------------------------------------------
#int_RB
void  RB_isr(void)       // Zero Cross Detect _ to Pin RB5         
{
   int8 current;
   static int last=0;
   TRAIC_GATE=1;
   set_timer0(firing_angle);
   enable_interrupts(INT_TIMER0);       //Enable timer0 interrupt
   set_tris_b(0xF0);
   current=input_b();
   last=current;
}
//------------------------------------------------------------------------------
#int_TIMER0
void  TIMER0_isr(void)
{
   disable_interrupts(INT_TIMER0);               //disable timer0 interrupt
   if(TRAIC_GATE)
   {
      output_low(PIN_A2);
      TRAIC_GATE=0;
      set_timer0(fire_on_delay);
      enable_interrupts(INT_TIMER0);
   }
   else if(!TRAIC_GATE)
   {
      output_high(PIN_A2);
      TRAIC_GATE=1;
   }
}



void main()
{

   port_b_pullups(TRUE);
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
//   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_128);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   TRAIC_GATE=0;
   count= 170;
   initialize_ports();
   initialize_variables();
   enable_interrupts(INT_RB);
//   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   while(TRUE)
   {
     count= getc();
     initialize_variables();
     delay_ms(600);
   }
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void initialize_ports(void)
   {
   output_low(PIN_A0);
   output_low(PIN_A1);
   output_high(PIN_A2);
   output_float(PIN_A3);
   output_float(PIN_A4);
   output_float(PIN_A5);

//   output_high(PIN_C0);
//   output_float(PIN_C1);
//   output_high(PIN_C2);
//   output_float(PIN_C3);
//   output_float(PIN_C4);
   output_high(PIN_B5);
   }
//------------------------------------------------------------------------------
void initialize_variables(void)
{
     firing_angle = count;
     fire_on_delay= 400-firing_angle;
}
//------------------------------------------------------------------------------



Master Code
Code:

#define MINIMUM_FIRING_ANGLE   170
#define MAXIMUM_FIRING_ANGLE   240
#define CH1_UP    0x0a
#define CH1_DOWN  0x0b
//-------------------------------------------------------------------------------
void initialise_ports(void);
int8 chk_status(void);
unsigned int8 last_fire_value;
//------------------------------------------------------------------------------
int8 ScanKeys(void)
{
/*   union {
      struct {
         int1 key1;
         int1 key2;
         int1 key3;
         int1 key4;
         int1 key5;
         int1 key6;
         int1 key7;
         int1 key8;
      } s;
      int8 b;
   } keys;
   
   keys.s.key1 = input(PIN_KEY1);
   keys.s.key2 = input(PIN_KEY2);
   keys.s.key3 = input(PIN_KEY3);
   keys.s.key4 = input(PIN_KEY4);
   keys.s.key5 = input(PIN_KEY5);
   keys.s.key6 = input(PIN_KEY6);
   keys.s.key7 = input(PIN_KEY7);
   keys.s.key8 = input(PIN_KEY8);
   
   delay_ms(50);  //debounce keys
   
   if(keys.s.key1 != input(PIN_KEY1))
      keys.s.key1 = ~keys.s.key1;
   
   if(keys.s.key2 != input(PIN_KEY2))
      keys.s.key2 = ~keys.s.key2;
   
   if(keys.s.key3 != input(PIN_KEY3))
      keys.s.key3 = ~keys.s.key3;
   
   if(keys.s.key4 != input(PIN_KEY4))
      keys.s.key4 = ~keys.s.key4;
     
   if(keys.s.key5 != input(PIN_KEY5))
      keys.s.key5 = ~keys.s.key5;
     
   if(keys.s.key6 != input(PIN_KEY6))
      keys.s.key6 = ~keys.s.key6;
     
   if(keys.s.key7 != input(PIN_KEY7))
      keys.s.key7 = ~keys.s.key7;
     
   if(keys.s.key8 != input(PIN_KEY8))
      keys.s.key8 = ~keys.s.key8;
     
   return(keys.b);*/
     unsigned int8 key_data;
     unsigned int8 dimming_value;
     
     dimming_value=last_fire_value;
     key_data=chk_status();               //key_detection
     if(key_data != 0xFF)
      {
        delay_ms(20);                     // Debounce
        output_low(PIN_C3);
        key_data=chk_status();            //Key_confirmation
        if(key_data == 0xfb)
        {
            output_toggle(PIN_C3);
            if(last_fire_value < 240)
            {
               dimming_value++;
            }
            else
            {
               dimming_value=240;
            }
        }
        if(key_data == 0xf7)
        {
            output_toggle(PIN_C3);
            if(last_fire_value > 170)
            {
               dimming_value--;
            }
            else
            {
               dimming_value=170;
            }
        }
     }
     last_fire_value =dimming_value;
     return(dimming_value);
}   
//------------------------------------------------------------------------------

void main()
{
   int8 PrevResult, CurrResult;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   last_fire_value=MINIMUM_FIRING_ANGLE;
   PrevResult = ScanKeys();
   
   while(TRUE)
   {
   CurrResult = ScanKeys();
     
    if(CurrResult != PrevResult)
    {       
       PrevResult = CurrResult;
    }
   }
}
//------------------------------------------------------------------------------
void itialise_ports(void)
{
   output_high(PIN_A0);
   output_high(PIN_A1);
   output_high(PIN_A2);
   output_high(PIN_A3);
   output_high(PIN_A4);
   output_high(PIN_A5);

   output_low(PIN_C0);
   output_low(PIN_C1);
   output_low(PIN_C2);
   output_low(PIN_C3);
   output_high(PIN_B4);
   output_high(PIN_B5);
}
//------------------------------------------------------------------------------
int8 chk_status(void)
{
   int8 temp;
   temp=((input_B()<<2) & 0xC0);
   temp=((input_A() & 0x3F) | temp);
   return temp;
}
//------------------------------------------------------------------------------




Please Guide us what steps i want to follows if any guide me i will very appreciating.

Prafulla
_________________
I m Working as PIC Programmer Fresher
Mike Walne



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

View user's profile Send private message

PostPosted: Fri Jun 28, 2013 2:33 am     Reply with quote

Break the problem into bite sized chunks.

The posted code is not complete and compilable, so we can't copy and paste to test.

You're very vague about what works and what does not, we have to guess.

Mike
temtronic



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

View user's profile Send private message

PostPosted: Fri Jun 28, 2013 5:47 am     Reply with quote

Mike is right..
I'd get rid of the 'master' code, RS485, etc. Put everything into the 'slave' and get it up and running.
Put in say a table of firing angles (every 10*) and cycle through them in 5 second intervals to confirm the phase control is properly working. Once that's done then work on the keypad interface (but in the same PIC). Again, confirm it works them merge the two. Confirm that works...

THEN

..split the program in half where the master scans the keypad and sends the slave the command.

You've got way too much going on to figure out what's busted.

also whenever using the hardware UART, always add 'errors' to the use rs232('''options....")

hth
jay
asmboy



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

View user's profile Send private message AIM Address

beating a tired dog ??
PostPosted: Fri Jun 28, 2013 12:46 pm     Reply with quote

Haven't we been through the bulk of this problematic code already with :

http://www.ccsinfo.com/forum/viewtopic.php?p=176948&highlight=#176948


If you can't do RS-485 - GET rid of all the messed up zero cross and other unrelated overburden - and just show a short program that features your new problem.

The attempt at "TRAIC" control is in the same state of repair and function as back them and only adds to the confusion.
SIMPLIFY please
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