PIC İLE Sinüsoidal Dalga Üretmek

Başlatan mhtgkc, 06 Nisan 2013, 01:27:28

mhtgkc

Merhaba arkadaşlar bi program yazdım ama sinusu tam elde edemedim bozulmalar oluyor nasıl düzeltebilirim bunu yardımcı olurmusunuz.

#include <16F877A.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
//#FUSES RESERVED                 //Used to set the reserved FUSE bits

#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C7,rcv=PIN_C6)

const long int sinus50[]={0x20, 0x22, 0x25, 0x27, 0x2A, 0x2C, 0x2F,0x31, 0x33, 0x35, 0x37, 0x39,
                    0x3A, 0x3C, 0x3D, 0x3E, 0x3E, 0x3F, 0x3F,0x3F, 0x3F, 0x3F, 0x3F, 0x3E,
                    0x3D, 0x3C, 0x3A, 0x39, 0x37, 0x35, 0x33,0x31, 0x2F, 0x2D, 0x2A, 0x28,
                    0x25, 0x23, 0x20, 0x1D, 0x1B, 0x18, 0x16,0x13, 0x11, 0x0E, 0x0C, 0x0A,
                    0x08, 0x07, 0x05, 0x04, 0x02, 0x01, 0x01,0x01, 0x01, 0x01, 0x01, 0x01,
                    0x01, 0x01, 0x02, 0x03, 0x04, 0x06, 0x07,0x09, 0x0B, 0x0D, 0x10, 0x12,
                    0x14, 0x17, 0x19, 0x1C, 0x1F};

int1 xxx;
char sinuss_idx=0;

#int_timer2
timer2()
{
   //set_timer2(24);
   if(sinuss_idx > 77)
   {
      sinuss_idx = 0;
   }
   set_pwm1_duty(sinus50[sinuss_idx++]);
   xxx = 1;
   output_bit( PIN_B7, 1);
}

#org 0x1F00, 0x1FFF void loader16F877A(void) {} //Bu satır bootloader kullanımı için

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_2(T2_DIV_BY_4,160,2); //T2_DIV_BY_4,80,2=>100Hz   T2_DIV_BY_4,160,2=>50Hz
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);

   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(GLOBAL);
   
   for(;;)
   {
      output_bit( PIN_B7, 0);
   }
}

crasftsman