PWM in LMD18200 and 16F628a

Status
Not open for further replies.

evilopinions

New Member
Just trying to get this code to work.....

Code:
#define INC  PORTA.F5
#define DEC  PORTA.F6
#define STOP PORTB.F2
#define DIR  PORTA.F7


char *txt1 = "ACTUAL: " ;
char *txt2 = "REQ: "    ;
int act    = 0          ;          // Stores the actual number of pulses
int revsreq = 0        ;
char atxt[4]            ;          //
char rtxt[4]            ;
char duty_v = 100         ;

void main()
{
CMCON = 0x07; //digital mode
TRISA  = 0b00000100;
TRISB  = 0b00000100;
 PORTA.F3 =   0 ;
 PORTB.F3 =    1 ;
  PORTA.F2 =   1 ;
 }
/*LCD
//LCD_Custom_Config(&PORTB,7,6,5,4,1,&PORTA,1,0);
//Lcd_Custom_Cmd(LCD_CURSOR_OFF);          // Switches the cursor off
//Lcd_Custom_Out(1,1,"Group-J") ;          // Displays 'Group-J'
//Lcd_Custom_Out(2,1,"VEB-3001");          // Displays 'VEB-3001'
//delay_ms(500)          ;          // Delays the program for half a second

 //  Pulse Width Modulation
Pwm_Init(1000)         ;          // Sets the frequency at 1KHz
Pwm_change_duty(0)     ;          // Sets the duty cycle to 0 at start
Pwm_start              ;          // Initializes the PWM

// Timer 0
 OPTION_REG.T0SE = 0; //rising edge
OPTION_REG.T0CS = 1; //T0 Clock Source
OPTION_REG.PSA = 1;  //no prescaling
 TMR0 = 0;            //initialize timer0


     //GLOBAL INTERRUPT
INTCON.GIE = 1         ;          // Enables the global interrupt
 //while ever loop
 while(1)  {

          TMR0=0       ;           // Clears the count on timer0 as the loop starts
          delay_ms(1000);           // programs goes to sleep for one second
          act = TMR0   ;       // act stores the count on timer0 in one second

          duty_v =(revsreq - act)*1 + duty_v     ;
          if(duty_v>255){duty_v = 255;}
          if(duty_v< 0 ){duty_v =   0;}
          PWM_Change_Duty(duty_v);

          if(INC==1)
          {revsreq = revsreq+4;
           if(revsreq>40) {revsreq = 40;}
           }

          if(DEC=1)
          {revsreq =revsreq-4;
          if(revsreq<0){revsreq=0;}}

          if(DIR==1)
          {if(PORTA.F2 == 0)
            {PORTA.F2  =1;}
           if(PORTA.F2 ==1)
           {PORTA.F2=0;}
           }

          if(STOP==1)
          {PORTA.F3=1;}

          bytetostr(act/4,atxt);    // Changes actual pulses into revolutions and convert it into string
          Lcd_Custom_Out(1,1,txt1)    ;    // Displays "ACTUAL" on the LCD
          LCD_Custom_Out_CP(atxt)     ;    // append data


          bytetostr(revsreq/4,rtxt);// Changes required pulses into revolutions and convert it into string
          Lcd_Custom_Out(2,1,txt2)    ;    // Displays "REQ:" on the LCD
          Lcd_Custom_Out_cp(rtxt)     ;    // append data
          }
           }


Can someone actually look at it and tell me where am I going wrong...

Even the LCD is not functuning correctly...It lights up but displays nothing....

PIN 1,2,9 in 16F628a correspong to direction , Brake and PWM....(RA2 , RA3, RB3)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…