Esempio n. 1
0
void main() {
  InitMain();
  current_duty  = 200;                 // initial value for current_duty
  current_duty1 = 200;                 // initial value for current_duty1
  TRISA  = 0xFF;              // PORTA is input
  TRISB = 0xFF;                             // Set PORTB as input
  //PORTB = 0x00;
  PWM1_Start();                       // start PWM1
  PWM2_Start();                       // start PWM2
  PWM1_Set_Duty(0);        // Set current duty for PWM1
  PWM2_Set_Duty(0);       // Set current duty for PWM2
  adcon1 = 0b1000010;
  while (1) {                         // endless loop

    temp_res = ADC_Read(0);
    temp_res=temp_res*255.0/1024.0;
    newduty=temp_res;
    if(RB0_bit==1 && RB1_bit==0){
         PWM1_Set_Duty(newduty);
         PWM2_Set_Duty(0);
    }else if(RB0_bit==0 && RB1_bit==1){
         PWM1_Set_Duty(0);
         PWM2_Set_Duty(newduty);
    }
    else{
         PWM1_Set_Duty(0);
         PWM2_Set_Duty(0);
    }
    

    Delay_ms(5);                      // slow down change pace a little
  }
}
Esempio n. 2
0
void main() {
trisb=0b11111011;
uart1_init(2400);
PWM1_Init(30000);
PWM1_Set_Duty(127);
PWM1_Start();
for(;;){
if(portb.f0==0)
{
uart1_write('a');
}while(portb.f0==0);
if(portb.f4==0)
{
uart1_write('a');
}while(portb.f4==0);
if(portb.f5==0)
{
uart1_write('b');
}while(portb.f5==0);
if(portb.f6==0)
{
uart1_write('c');
}while(portb.f6==0);
}

}
Esempio n. 3
0
void Interrupt(){
  unsigned int vcalc;
  unsigned long wts;
  unsigned short encVal = 0;
  unsigned char cs = 50;
  
  if (TMR1IF_bit)  // Timer1 Code
  {
      TMR1IF_bit = 0;
      TMR1H         = Hi(tmrOffset);
      TMR1L         = Lo(tmrOffset);
      if (wavSel == 0)
      {
         wts = (unsigned long)sizeof( envelope_table );
         vcalc = (envelope_table[x1]);
      }
      else if (wavSel == 1)
      {
         wts = (unsigned long)sizeof( envelope_table2 );
         vcalc = (envelope_table2[x1]);
      }
      x1+=xStep;
      if(x1 == wts)
      {
        xStep=1;
        x1 = 0;
        T1CON         = 0x00;
      }
      PWM1_Set_Duty( vcalc );
  }
}
Esempio n. 4
0
void alimentar(unsigned short tamanio) {
  PWM1_Start();                       // start PWM1
  PWM1_Set_Duty(90);
  Delay_ms(750);
  PWM1_Stop();
  if (tamanio == 'A'){
     Delay_ms(500);
   }
  else if (tamanio == 'B'){
     Delay_ms(1500);
   }
  else if (tamanio == 'C'){
     Delay_ms(2000);
   }
  else if (tamanio == 'D'){
     Delay_ms(2500);
   }
  PWM1_Start();
  PWM1_Set_Duty(30);
  Delay_ms(750);
  PWM1_Stop();
}
Esempio n. 5
0
void alimentar(unsigned short tama) {
  PWM1_Set_Duty(70);
  PWM1_Start();                       // start PWM1
  Delay_ms(1000);
  PWM1_Stop();
  if (tama = 65){
     Delay_ms(100);
   }
  else if (tama = 66){
     Delay_ms(150);
   }
  else if (tama = 67){
     Delay_ms(200);
   }
  else if (tama = 68){
     Delay_ms(250);
   }
  PWM1_Set_Duty(50);
  PWM1_Start();
  Delay_ms(1000);
  PWM1_Stop();
}
Esempio n. 6
0
void main()
{  ADCON0 = 0;         //adc =0
   ADCON1 = 0xF0;     // Set all A/D pins as digital I/O pins.
   TRISA = 0X00;
   TRISC = 0x00;
   PORTC = 0X00;
   PORTA = 0b01010000;
   PWM1_Init(5000);
   PWM2_Init(5000);
   Pwm1_Start();
   Pwm2_Start();
   while(1)
   {
   PWM1_Set_Duty(210);
   PWM2_Set_Duty(135);
   Delay_ms(10000);
   PWM1_Set_Duty(255);
   PWM2_Set_Duty(255);
   Delay_ms(10000);
   PWM1_STOP();
   PWM2_STOP();
}
}
Esempio n. 7
0
void Interrupt(){

  if(INTF_bit){    //External Interrupt occurred
  INTCON = 0;      //Disable all interrupts
  PORTB.F2 = 0;
  PORTD = 0;
  PWM1_Stop();
  }

  if (TMR1IF_bit){        //Timer1 Interrupt occurred
    TMR1IF_bit = 0;
    TMR1H         = 0x6D;
    TMR1L         = 0x84;
  dt = ADC_Read(0);   //Read analog value

  if (dt != dt0) {
  dt0 = dt;
  dt0 = dt0 >> 2;
  PWM1_Set_Duty(dt0);
  PWM1_Start(); 

  }

 }