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

Need help on pwm

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



Joined: 27 Jul 2007
Posts: 33

View user's profile Send private message Send e-mail

Need help on pwm
PostPosted: Wed Aug 22, 2007 8:10 am     Reply with quote

i am using pic18f2520 with 20mhz osc and i have to write a program which will drive a full bridge thyristor. The client will enter a set voltage. By triggering the thyristors with suitable pwm, i will force the output to the desired voltage. I am using version 3.212.
The pin configuraion is as follows(This is not code):
Code:



pic_pins        pic pins used as:

RA0..RA5   //to LEDS(not so important)

RC0      SW1
RC1      PWM2
RC2      PW1
RC3      SW2
RC4      SW3
RC5      SW4
RC6      --
RC7      --


RB0      Vout   //analog feedback input for voltage
RB1      Iout   //and current

RB2      RS   //  pins to LCD
RB3      E   //   
RB4      D4   //
RB5      D5   //
RB6      D6   //
RB7      D7   


When i compile it, an error occurs such as "A numeric expression must appear here ". I want to know if a pwm selection, (such below main() ), would be a good approach or would it be better to match a specific voltage value to a specific pwm? Are there any other mistakes? If yes can you help me how can i correct them?

Code:




#include <18F2520.h>
#device  adc=8
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)

#include "Flex_LCD.c"


#define     BUTON_UP       PIN_C0
#define     BUTON_DOWN     PIN_C3
#define     BUTON_ENTER    PIN_C4
#define     BUTON_BREAK    PIN_C5


/*----------GLOBAL VARIABLES-----------*/

int8     duty_value;     
int16    adc_value;
float    count_adc, LCD_voltage, Error;





//--------- LCD MENU ----------------//
                         

#INT_EXT           

float ext_isr(float volt,float amper)   
   {
          volt=0;


volt_set:     lcd_putc("\f");
              lcd_gotoxy(1,1);
              printf(lcd_putc,"volt set");
              delay_ms(1000);

              lcd_gotoxy(1,1);
              lcd_putc("\fvolt +");
              delay_ms(1000);

              lcd_gotoxy(1,2);
              lcd_putc("volt -");
              delay_ms(1000);

              lcd_gotoxy(1,1);
              printf(lcd_putc, "\f%3.2f", volt);



              if (input(BUTON_UP))
                 {
                  volt+=0.2;
                     if(volt>30)
                        volt=30;
                        printf(lcd_putc, "\fvolt=%3.2f", volt);

                 }


              if (input(BUTON_DOWN))
                  {
                  volt-=0.2;
                     if(volt<0)
                        volt=0;
                        printf(lcd_putc, "\fvolt=%3.2f", volt);
                  }

                    if (input(BUTON_ENTER))
                    return volt;
                    else
                    goto volt_set;
    }



/* ---------------- MAIN PROGRAM -------------------*/


int init_ADC(void);       
//float LCD_menu(float volt,float amper); 


void main()
{




int init_ADC(void)
{
  setup_adc_ports( ALL_ANALOG );
  setup_adc( ADC_CLOCK_DIV_2 );
  set_adc_channel( 12 );            //Sets A_to_D input to channel 12
  set_adc_channel(10);             
  delay_us(10);
}




        lcd_init();       
   set_tris_a(0b00000100);
   set_tris_b(0b00000011);
   set_tris_c(0b00111001);



      delay_ms(10);
      output_low(PIN_C2);                  // Set CCP1 output low
      setup_ccp1(CCP_PWM);                 // Configure CCP1 as a PWM
      output_low(PIN_C1);                  // Setup CCP2 output low
      setup_ccp2(CCP_PWM);                 // Configure CCP2 as a PWM


      setup_timer_2(T2_DIV_BY_1,255,1);   



pwm_calibration:     adc_value = read_ADC();
                     delay_us(10);

                 count_adc=((float)(adc_value/1023))*30;
                 LCD_voltage=ext_isr();
                 Error=LCD_voltage-count_adc;


                 if(Error>0.2)
                   {
                   ++duty_value;
                        if(duty_value>254)
                            duty_value=254;

                           set_pwm1_duty(duty_value);
                           set_pwm2_duty(duty_value);
                           printf(lcd_putc,"\fvolt=%3.2f",voltage);
                           goto pwm_kalibration;
                   }
                 if(Error<-0.2)
                     {--duty_value;
                        if(duty_value<1)
                           duty_value=1;

                           set_pwm1_duty(duty_value);
                           set_pwm2_duty(duty_value);
                           printf(lcd_putc,"\fvolt=%3.2",voltage);
                     }

                 if (Error<0.2 & Error>-0.2)
                       printf(lcd_putc,"\fvolt=%3.2",voltage);

                     goto pwm_calibration;


}
Ttelmah
Guest







PostPosted: Wed Aug 22, 2007 10:02 am     Reply with quote

An ISR, _never_ accepts a value, or returns a value. It must be declared as void (it makes no sense to have it accepting or returning a value, since you do not know _when_ it is going to occur in the main code, and there is nothing 'calling' it, to give it a value, or to have a value returned)...
Then you have 'init_ADC' declared to return an int, but returning nothing.
This routine, is then declared 'inside' main. This is not legal.
You declare an ISR, but never enable the interrupt.

Best Wishes
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