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

step mode vs adc
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Sun Oct 16, 2011 9:29 am     Reply with quote

asmallri wrote:
asmboy wrote:

in my experience:
relays take more time to CLOSE than to OPEN.


The [spam] is equally true. It often takes longer for a relay to open (as a result of the relay coil being de-energized) than for the contacts to close (when the relay coil is energized). There are lots of factors that contribute to this behaviour however one key consideration is the back EMF protection diode feeding current back into the relay coil as the relay's magnetic field collapses thereby prolonging the relay holding time.

so now, what requirement change \add ?
_________________
sahu
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Sun Oct 16, 2011 7:21 pm     Reply with quote

just back from a week end away - but if i was designing such a beast today
i would surely :

1- detect RMS AC input for the pic - averaged across a dozen cycles or more
2- detect input ac zero crossings
3- uses optically switched TRIACS
4- LOSE the mechanical relays
5- use dead band count/ timing after each adjustment to insure stability

i will think about this some more but i suspect the relays play a critical role in the trouble you are having too.

if you are locked in to a relay design - i would rewire it so that the relay contacts are:

1- SEQUENTIALLY tied logically
2- each level of voltage out pases through ALL contacts sets such that each contact selects either ITS step or the next LOWER step
3- after a switch - DELAY the next ref voltage reading // step select choice // to allow for relay closure time
4- ADD pic HYSTERESIS logic to make sure you won't "step dither" when you are right at the switch point between two voltages
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 10:55 am     Reply with quote

asmboy wrote:
just back from a week end away - but if i was designing such a beast today
i would surely :

1- detect RMS AC input for the pic - averaged across a dozen cycles or more
2- detect input ac zero crossings
3- uses optically switched TRIACS
4- LOSE the mechanical relays
5- use dead band count/ timing after each adjustment to insure stability

i will think about this some more but i suspect the relays play a critical role in the trouble you are having too.

if you are locked in to a relay design - i would rewire it so that the relay contacts are:

1- SEQUENTIALLY tied logically
2- each level of voltage out pases through ALL contacts sets such that each contact selects either ITS step or the next LOWER step
3- after a switch - DELAY the next ref voltage reading // step select choice // to allow for relay closure time
4- ADD pic HYSTERESIS logic to make sure you won't "step dither" when you are right at the switch point between two voltages

Dear sir my English is very bad. If possible can you give example ?
_________________
sahu
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Mon Oct 17, 2011 12:38 pm     Reply with quote

Re the schematic - confusing and drawn such that taps are selected at both ends ??

Here is a (I hope clearer) simpler - intrinsically safe way to change taps.
http://64.128.110.53/SWTAP.pdf

-- if you are going to use relays at all.
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 1:03 pm     Reply with quote

asmboy wrote:
Re the schematic - confusing and drawn such that taps are selected at both ends ??

the schematic - don't confuse
i\p = input
o\p= output
ok
Quote:
Here is a (I hope clearer) simpler - intrinsically safe way to change taps.
http://64.128.110.53/SWTAP.pdf

it is confusing for me here only 1 i\p ,
where o\p ?

this is wiring daygram of relay canection.
_________________
sahu


Last edited by sahu77 on Sun Sep 30, 2012 9:14 am; edited 1 time in total
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Mon Oct 17, 2011 4:17 pm     Reply with quote

refer to

http://64.128.110.53/swtap.pdf

as updated


auto former taps assuming tap points work for the design

RELAY STATES: ( SHOWN DE ENERGIZED - in NC state)

Vin?? K1 K2 K3 K4
-------------------------------------------
highest off off off off // Greatest step DOWN

2nd high off on off off

NORMAL on on off off //NO STEP chg

2nd low on on on off

lowest on on on on // step UP max
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 11:04 am     Reply with quote

asmboy wrote:
refer to

http://64.128.110.53/swtap.pdf

as updated


auto former taps assuming tap points work for the design

RELAY STATES: ( SHOWN DE ENERGIZED - in NC state)

Vin?? K1 K2 K3 K4
-------------------------------------------
highest off off off off // Greatest step DOWN

2nd high off on off off

NORMAL on on off off //NO STEP chg

2nd low on on on off

lowest on on on on // step UP max

yes it may possible .
_________________
sahu
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Wed Dec 07, 2011 10:06 pm     Reply with quote

Pl reply me, ASMBOY
_________________
sahu
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Tue Dec 13, 2011 11:53 am     Reply with quote

I think use flag when I move one case to another case. But confuse how ?
Anybody guide me, please.
_________________
sahu
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Sun Jan 01, 2012 7:27 am     Reply with quote

Hi all - happy new year 2012 im wating for reponse. Pl guied me...
_________________
sahu
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Jan 01, 2012 7:53 am     Reply with quote

Look in Wikipedia for "Finite-state machine". It is a good introduction to how software can move from one case or state to another using flags.
_________________
The search for better is endless. Instead simply find very good and get the job done.
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Thu Jan 12, 2012 12:25 pm     Reply with quote

something wrong here ???
now i use this
Code:
 
            switch (step_mode)
{
           case 1:
    // Low Voltage protection is done here
   //Low Voltage protection enable. if SW2 is always on(conect with GND).
  //if SW2 is always off(no conect with GND & +5 volt.) Low Voltage protection disable

  // if ((ch<440) && ((input(SW2)==0) || (QuickStart_flag == 1)))
   //      return(LOW_VOLTAGE); 
         
          if (ch < 566)
   if(a==0)
   {
          {
            relaycontrol=0x1;
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
            break;
           }
    }
          if (ch >= 664) 
  {
   if(b==0)
          {
            relaycontrol=0x2;
            output_high(RL3);
            output_low(RL2);
            output_low(RL1);
             break;
          }
}
          if (ch > 831) 
          {
              step_mode = 2;  // goto step 2
              break;
          }   
         
     case 2:
     if (ch < 540) /
          {
                step_mode = 1;  // Callback to step 1
                break;
          }
          if (ch >= 547)  /
{
   if(c==0)
          {
            relaycontrol=0x4;
              output_low(RL3);
              output_high(RL1);
              output_low(RL2);
                break;
           }
}
          if (ch >= 685)   
{
   if(d==0)
          {
            relaycontrol=0x8;
            output_high(RL3);
            output_low(RL2);
            output_high(RL1);
               break;
          }
}
                    if (ch > 877) 
          {
              step_mode = 4;  // goto step 2
                          break;
          }   

     case 4:
     if (ch < 590)
          {
                step_mode = 2;  // Callback to step 2
                break;
          }
          if (ch >= 596) 
{
   if(e==0)
          {
            relaycontrol=0x10;
              output_low(RL3);
              output_high(RL1);
              output_high(RL2);
              break;
           }
}
          if (ch >= 705)   
{
   if(f==0)
          {
            relaycontrol=0x20;
            output_high(RL3);
            output_high(RL2);
            output_high(RL1);
            break;
          }
}

     // High Voltage protection is done here
   if (ch>1500)
      return(HIGH_VOLTAGE);

   //We have got here, so voltage should be normal
   return(NORMAL_VOLTAGE);
}
}

but its do mcu hang .
right now test as
Code:
                    _________
              Vdd   | 1  14 |  Vss                    ----^^|^--- +5volt
  (I) SW1 --> RA5   | 2  13 |  AN0 <-- ADC_Value (I)---wiper
  (I) SW2 --> RA4   | 3  12 |  RA1 --> RL1 (O)
             MCLR   | 4  11 |  RA2 --> N\C NOT  use
  (O)  L1 <-- RC5   | 5  10 |  RC0 --> RL2 (O)
  (O)  L1 <-- RC4   | 6   9 |  RC1 --> RL3 (O)
  (O) BZR <-- RC3   | 7   8 |  RC2 --> RL4 (O)
                    ---------

when i rotate trimer wiper ,change adc volt its show only this
Quote:
if (ch >= 685) // //now case 2 >/// 694 to 870 //703
{
if(d==0)
{
relaycontrol=0x8;
output_high(RL3);
output_low(RL2);
output_high(RL1);
break;
}
}

nothing change .so guide me where wrong ....
_________________
sahu
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 11:00 am     Reply with quote

Anybody help me ...
need help
_________________
sahu
temtronic



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

View user's profile Send private message

PostPosted: Tue Feb 07, 2012 2:06 pm     Reply with quote

I can understand your confusion as that switch-case code is very,very hard to read !

I would take the code...
Code:

{
            relaycontrol=0x1;
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
            break;
           }

and create a function something like...
Code:

void power_level_1(void) {
{
            relaycontrol=0x1;
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
}

then call that function when the switch-case condition is true.

This will 'cleanup' the code,making it easier to read and debug.
there appear to be 6 different combinations ao you'ld need 6 new functions(subroutines).

In some 'cases' you have IF conditions within the case..
It might be easier to read if you combine the two conditions into one.

There's a LOT of brackets and it's hard to 'see' the logic and flow of the
testing you're doing
sahu77



Joined: 08 Sep 2011
Posts: 202

View user's profile Send private message

PostPosted: Wed Feb 08, 2012 11:06 am     Reply with quote

Thank SIR Mr. temtronic for your guidance.
Now i change code as you say & also change code for lcd 16*2 for display. My step position & remove some port of my code, because ROM is not enough for both (lcd + some port).
So i decide remove some port & display only step position, high or normal volt position.
Now code are as...
Code:

/*****************************************************************************
  Function ProcessMains
  Reads ADC_Value and returns NORMAL_VOLTAGE, HIGH_VOLTAGE, LOW_VOLTAGE
 ****************************************************************************/
int ProcessMains(void)
{
   int16 ch_1;
   ch_1 = getchreading(0);              // Extract volts (thousands of millivolts) from AN1
   //printf("%Lu\n",ch_1);
 
            switch (step_mode)
          {
           case 1:
          if (ch_1 < 660)//95 volt
          {
          power_level_1();
            break;
           }
          if (ch_1 >= 666)  //115 v
          {
          power_level_2();
            step_mode = 2;  // goto step 2
            break;
          }
         
     case 2:
     if (ch_1 < 645) //now  case 2 < 115v
          {
                step_mode = 1;  // Callback to step 1
                break;
          }
          if (ch_1 < 650)  // //now  case 2 < 137v
          {
          power_level_3();
                break;
           }
          if (ch_1 >= 770)    // //now  case 2 > 137v to 170 v
          {
          power_level_4();
               step_mode = 3;  // goto step 3
               break;
          }

     case 3:
     if (ch_1 < 645) //now  case 2 < 115v
          {
                step_mode = 2;  // Callback to step 2
                break;
          }
          if (ch_1 < 650)  // //now  case 3
          {
          power_level_5();
              break;
           }
          if (ch_1 >= 770)    // //now  case 4
          {
          power_level_6();
            break;
          }


}
     // High Voltage protection is done here
   if (ch_1>1000)
      return(HIGH_VOLTAGE);

   //We have got here, so voltage should be normal
   return(NORMAL_VOLTAGE);
}
 /***************************************************************************
  Function power_level on selected step
 ****************************************************************************/
void power_level_1(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_1\n");
}

void power_level_2(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_2\n");
}

void power_level_3(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_3\n");
}

void power_level_4(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_4\n");
}

void power_level_5(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_5\n");
}

void power_level_6(void) {
{
            output_low(RL1);
            output_low(RL2);
            output_low(RL3);
     LCD_PutChar("\f step_6\n");
}

Normal volt position. Ok show as I want.
But high or power_level_1 etc are not work as I want.
I use flex lcd driver.
_________________
sahu
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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