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 support@ccsinfo.com

Pwm decoder from rc transmitter

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Tufican



Joined: 23 Feb 2011
Posts: 10
Location: Turkey- izmir

View user's profile Send private message

Pwm decoder from rc transmitter
PostPosted: Thu Jan 26, 2012 5:37 am     Reply with quote

I write this code. It reads 4 pwm signals from a remote controller from 1 pin with 4 to 1 multiplexer.

You can use this program for your quadcopter multicopter helicopter or plane.

You can add imu sensors and another sensors.
The program is working good and output data is coming from uart.
I use 74153 mux.
Mux selector pins is pin_d0 and pin_d1
and pic 18f4580 8mhz internal with 4xpll 32mhz.

Data format is
0*0*0*0
If every channels will left
data is
-8*-8*-8*-8

If every channels will right
8*8*8*8
coming from uart

loop time is 20ms

Code:

#include <18F4580.h>
#fuses HS,NOPROTECT,NOLVP,NOWDT
#use delay(internal=8Mhz , clock=32Mhz)

#use rs232(baud=38400, xmit=PIN_C6, rcv=PIN_C7)

#use fast_io(b) //Port yönlendirme komutları B portu için geçerli
int a=0;
int t=0;
int sira=1;
int k[5];

#INT_CCP1   // INT_CCP1 kesmesi fonksiyonu
void yakala1_kesmesi ()
{
if(a==1)
a=0;
else
a=1;
}

void main() {
   setup_psp(PSP_DISABLED);        // PSP birimi devre dışı
   setup_spi(SPI_SS_DISABLED);     // SPI birimi devre dışı
 
   setup_adc_ports(NO_ANALOGS);    // ANALOG giriş yok
   setup_adc(ADC_OFF);             // ADC birimi devre dışı

   set_tris_b(0x00);   // B portu komple çıkış
   set_tris_d(0x00);   // B portu komple çıkış
   set_tris_c(0x07);   // RC0, RC1 ve RC2 pini giriş

   output_b(0x00); // İlk anda B portu çıkışı sıfırlanıyor
   output_d(0x00); // İlk anda B portu çıkışı sıfırlanıyor
   setup_ccp1(CCP_CAPTURE_re); // CCP1 kesmesi yükselen aktif// fe olursa düşen
 
   CCP_1_HIGH=0x00; // CCPR1H kaydedicisi sıfırlanıyor
   CCP_1_LOW=0x00;  // CCPR1H kaydedicisi sıfırlanıyor
 
   enable_interrupts(INT_CCP1);  // INT_CCP1 kesmesi aktif yapılıyor
   enable_interrupts(GLOBAL);    // Aktif edilen kesmelere izin ver
   
   k[1]=0;
   k[2]=0;
   k[3]=0;
   k[4]=0;
   
   Delay_ms(10);
   printf("START!");
   Delay_ms(10);

   while(TRUE)
   {
   output_d(sira-1);
   //delay_ms(1);
   setup_ccp1(CCP_CAPTURE_re);
 while(a==0)
 {
 //output_d(1);
 }
 if(a==1)
 {
 setup_ccp1(CCP_CAPTURE_fe);
 while(a==1)
 {
 t++;
 delay_us(15);
 }}
 a=0;
 
 k[sira]=(t+160);

 sira++;

  if(sira==5)
 {
 printf("%d*%d*%d*%d"k[1]*(-1),k[2],k[3]+25,k[4]);

 sira=1;
// delay_ms(100);
 }

 t=0;

}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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