|
|
View previous topic :: View next topic |
Author |
Message |
hwwspace Guest
|
IF statment |
Posted: Thu Nov 04, 2004 3:40 am |
|
|
Hi,
I am a new one to use CCS C compiler. I am using 16F73 with CCS PCM 3.211 Compiler. I have some problem with my code. I want to get the atan value from two inputs AN0 and AN1, then output PWM in ccp1. Is there someone can help me?
the code is following:
Code: |
#include <16F73.h>
#include <math.h>
#device adc=8
#use delay(clock=2000000)
#fuses NOWDT,XS, NOPUT, NOPROTECT, BROWNOUT
void main() {
float valueX, valueY, data, angle;
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,255,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
while(true){
set_adc_channel(0);
delay_us(10);
valueX = read_adc();
set_adc_channel(1);
delay_us(10);
valueY = read_adc();
valueX = (valueX - 128) / 128;
valueY = (valueY - 128) / 128;
data = valueY / valueX;
if(valueX > 0){
if(valueY > 0)
angle = atan(data);
else
angle = 6.2831853 + atan(data);
}
else{
angle = 3.14159265 + atan(data);
}
angle = angle * 1024 / (2.0 * PI);
set_pwm1_duty((long int) angle);
}
}
|
|
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Thu Nov 04, 2004 8:36 am |
|
|
A couple of suggestions:
Enable PUT in your #fuses statement.
Cast your adc value to a float.
i.e. valueX = (float)read_adc(); _________________ David |
|
|
|
|
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
|