|
|
View previous topic :: View next topic |
Author |
Message |
switchblademaster Guest
|
Analog input |
Posted: Sat Nov 07, 2009 11:17 am |
|
|
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
|
|
|
switchblademaster Guest
|
|
Posted: Sat Nov 07, 2009 12:04 pm |
|
|
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
|
|
Posted: Sat Nov 07, 2009 12:12 pm |
|
|
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
|
|
Posted: Sat Nov 07, 2009 12:36 pm |
|
|
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 |
|
|
|
|
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
|