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

Formula for Current Transducer Model LTS 15 NP
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Mon May 12, 2014 7:18 am     Reply with quote

this is a fragment,
NOT a functioning, CCS compilable program.

it will not compile as is.

if it won't compile - i won't bother.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon May 12, 2014 7:24 am     Reply with quote

Hi,

It's also a fragment with glaring errors:

Code:

setup_adc_ports


John
ruth



Joined: 14 Apr 2014
Posts: 11

View user's profile Send private message

PostPosted: Mon May 12, 2014 9:02 am     Reply with quote

sorry,make trouble to u all..this is my functioning program
Code:

#include <18F4620.h>                   // PIC18F4620 HEADER FILE
#fuses HS,NOWDT,NOLVP,NOPROTECT        // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING
#device adc=10                        // USE 10 BIT ADC QUANTIZATION
#use delay (clock=20M)                  // 20 MHZ CRYSTAL
#include <lcd.c>                       // LCD DISPLAY HEADER FILE
#include <math.h>



#define SW1             PIN_B0
#define SW2             PIN_B1
#define LED1            PIN_B6
#define LED2            PIN_B7
#define AN0_AN2            0Xc8             // PIN_A0 till PIN_A2





#define LCD_E       PIN_D0             // PIN E   
#define LCD_RS      PIN_D1             // PIN RS   
#define LCD_RW      PIN_D2             // PIN RW
#define LCD_D4      PIN_D4             // PIN D4   
#define LCD_D5      PIN_D5             // PIN D5   
#define LCD_D6      PIN_D6             // PIN D6
#define LCD_D7      PIN_D7             // PIN D7   


float current;
float v_current;
int i,a;
float value,mean,s;
float v_value,v_mean;
////////////////////////////////////////////////////////////////////////////////

void read_analog();                 //current analog
void v_read_analog();               //voltage analog

void main()
{

 
lcd_init();

setup_adc_ports(AN0_AN2);                //Configure AN0 and AN2
setup_adc(ADC_CLOCK_DIV_32);


delay_ms(200);


 

while(TRUE)
  {
 
if(!input(SW1))
 {


while (true)
{

 set_adc_channel(0); //ADC channel = AN0,AN0 ready for sampling
 current=read_analog();
 
   mean=value/10;
   
  delay_ms(200);
 set_adc_channel(2); //ADC channel = AN2,AN2 ready for sampling
 
v_current=v_read_analog();
 
   v_mean=v_value/10;

      delay_ms(200);
     
 output_high(LED1);
 read_analog();
  v_read_analog();
 
    printf(lcd_putc, "\fI=%fA",mean);
   
    printf(lcd_putc, "\nV=%f",v_mean);
   
}

 }
 
 
ELSE if(!input(SW2))
{

while (true)
{
 set_adc_channel(0); //ADC channel = AN0,AN0 ready for sampling
 current=read_analog();
 
   mean=value/10;
     delay_ms(200);
 set_adc_channel(2); //ADC channel = AN2,AN2 ready for sampling
 
v_current=v_read_analog();
 
   v_mean=v_value/10;
         delay_ms(200);
     
 output_high(LED2);
 read_analog();
  v_read_analog();
s=value*v_value;   
   printf(lcd_putc, "\fP=%fW",s);

  }

}

  }
  }
 
 

void read_analog()
 {

current=0;
for (i=0; i<=9;++i)
{
delay_ms(2);
value=read_adc();


 

}
 

  }

void v_read_analog()
 {

v_current=0;
for (a=0; a<=9;++a){
delay_ms(2);
v_value=read_adc();






}
   
 }
 
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Mon May 12, 2014 11:25 am     Reply with quote

Code:

if(!input(SW1))
 {


while (true)
{


how about you find and show me
the EXIT condition for this construct above ??
DITTO:
ELSE if(!input(SW2)) ........
ruth



Joined: 14 Apr 2014
Posts: 11

View user's profile Send private message

PostPosted: Mon May 12, 2014 11:40 am     Reply with quote

asmboy,
it is means that i should put "end if" after i use "if"and put "end else if" after i use "else if"?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon May 12, 2014 12:22 pm     Reply with quote

Hi ruth/low,

Asmboy already pointed you to the issue on the last page! You stated the problem as:

Quote:

the problem i encountered is i cant direct change the display from button 1 to button 2 (i only can press button 1, then reset it before i press button 2).


Your code is doing it this way as that is the way you coded it! As coded, SW1 is always evaluated first, and if it's low, SW2 will never be evaluated!

This is really more of a 'design philosophy' problem. For example, you have two operational states, so why do you need two switches? With two switches, it's always going to operate 'oddly'! Why not do one thing then SW1 is high, and another thing when it's low?

John
Mike Walne



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

View user's profile Send private message

PostPosted: Mon May 12, 2014 2:35 pm     Reply with quote

I support ezflyr on this one.

I doubt that any part of your code has been properly tested and shown to work as intended.

You are asking for help, yet none of the code does what you claim.

1) You are transfixed on dealing with what the buttons do.
2) The voltage and current procedures do not measure averages.

Work on the KISS principle.

Code in small. easy to manage sections.
Test that each section works as it should.
Move on to the next section.
Stitch all the sections together.

Mike
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
Page 3 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