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

Analog input

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







Analog input
PostPosted: Sat Nov 07, 2009 11:17 am     Reply with quote

This is my code:
Code:

set_adc_channel( 0 );
delay_us(20);
RIGHT_2 = read_adc();
R2V = (3 * RIGHT_2);
printf("%lu voltage6 \n",R2V);
delay_ms(300);

I want to multiply my analog input by 3, however this does not happen. The analog value stays as what the ADC reads. Anybody can help me?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 07, 2009 11:58 am     Reply with quote

Post a complete, compilable ADC test program, showing the variable
declarations. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
switchblademaster
Guest







PostPosted: Sat Nov 07, 2009 12:04 pm     Reply with quote

Code:
#include <18f4520.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#use rs232 (DEBUGGER)

  int CENTER_L;
  int CENTER_R;
  int LEFT_1;
  int LEFT_2;
  int RIGHT_1;
  int RIGHT_2;
  int set_point=60;
  float sp = 2.5;
  int Kp = 7;
  float Kd = 0.8;
 
  int1 i;
  int MAX_PWM = 1023;
  int MIN_PWM = 50;
  int MAX = 1023;
  int MIN = 60;
  float average, error, total_error;
  float Perr,Derr, P, D;
  float Previous_error = 0;
  long L2V, L1V, R2V, R1V, LC, RC;
  float PWM,PDpwm;

void main()
{
long reading;
setup_adc_ports(AN0_to_AN1);
setup_adc( ADC_CLOCK_INTERNAL );


while(TRUE)
      {
   
        set_adc_channel( 0 );
         delay_us(20);
         RIGHT_2 = read_adc();
         R2V = (3 * RIGHT_2);
         printf("%lu voltage6 \n",R2V);
         delay_ms(300);
      }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 07, 2009 12:12 pm     Reply with quote

In CCS, an 'int' is an 8-bit unsigned integer. This applies to PCB, PCM
and PCH, but not to the PCD compiler. You can use 'int16' to declare
a 16-bit unsigned integer. To fix your problem, you need to change
some of your variable declarations.
switchblademaster
Guest







PostPosted: Sat Nov 07, 2009 12:36 pm     Reply with quote

WELL THAT MAKES SENSE LOL!!!!!!!

I now say I had the reading from the ADC as an int........my carelessness

Thanks again...........you r very helpful
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