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

Servo motor control and ADC

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



Joined: 22 Jul 2011
Posts: 1

View user's profile Send private message

Servo motor control and ADC
PostPosted: Fri Jul 22, 2011 8:53 pm     Reply with quote

I'd like to control a servo motor with PWM using TMR1 and 2,
while PIC always observes 7 sensors with ADC.

My compiler is PCM. PIC is 16F1827.
When I drive ADC in the "while(1){}",
( ex.)
Code:

set_adc_channel(2);
delay_us(15);
ax=read_adc();     

PWM signal stops after a certain time.
I'd like to make to work 7 ADC in the "while".

Do I forgot some resets?
Please tell me.

Code:

#include <16F1827.h>
#fuses INTRC_IO,CLKOUT,PUT,NOPROTECT,NOWDT,NOMCLR,BROWNOUT,NOLVP,IESO

#device ADC=8
#use delay(CLOCK=4000000)
#use rs232(BAUD=9600, XMIT=PIN_B5, RCV=PIN_B1)

long width;

#int_CCP1
void ccp1_int()
{
 output_low(PIN_B3);
}

#int_CCP2
void ccp2_int()
{
 if(CCP_1 != 0x0000)
  {
   output_high(PIN_B3);
  }
 set_timer1(0x0000);
}

void main()
{
 char ax,ay,az,a_pitch,a_roll,a_yaw,thermo;

 setup_oscillator(OSC_4MHZ);

 setup_adc_ports(sAN2 | sAN3 | sAN0 | sAN5 | sAN6 | sAN8 | sAN10 | VSS_VDD);
 
 setup_adc(ADC_CLOCK_DIV_32);
 
 setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
 setup_ccp1(CCP_COMPARE_INT);
 setup_ccp2(CCP_COMPARE_INT);
 set_timer1(0x0000);
 width=500;
 CCP_1=width;
 CCP_2=20000;

 enable_interrupts(INT_CCP1);
 enable_interrupts(INT_CCP2);
 enable_interrupts(GLOBAL);

 set_tris_a(0b00101101); //7?,6CLKout,5inputonly,4LED,3AN3(ay),2AN2(ax), 1LED,0AN0(az)
 set_tris_b(0b11010110); //7AN6,6AN5 5TX 4AN8 3CCP1 2AN10(thermo) 1RX 0?

 output_low(PIN_A7);;output_low(PIN_A1);output_low(PIN_A4);
 output_low(PIN_B3);output_low(PIN_B0);

 output_high(PIN_A4);
 delay_ms(500);
 output_low(PIN_A4);
 delay_ms(500);
 
 while(1)
  {
//   set_adc_channel(2);
//   delay_us(15);
//   ax=read_adc();
/*
   set_adc_channel(3);
   delay_us(15);
   ay=read_adc();
   set_adc_channel(0);
   delay_us(15);
   az=read_adc();
   set_adc_channel(5);
   delay_us(15);
   a_pitch=read_adc();
   set_adc_channel(6);
   delay_us(15);
   a_roll=read_adc();
   set_adc_channel(8);
   delay_us(15);
   a_yaw=read_adc();
   set_adc_channel(10);
   delay_us(15);
   thermo=read_adc();
*/
  }
}
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