pulse generation problem

Discussion in 'Programmer's Corner' started by lihle, Apr 4, 2010.

  1. lihle

    Thread Starter Active Member

    Apr 12, 2009
    83
    3
    guys
    help me out with a sample code to generate a pulse wave, where by i have to give the duty circle and the time.
    duty cycle/100*period=Time constant.

    lihle
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    If you have an internal timer, think about relating the time to count a value to zero to the pulse.
     
  3. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    What pulse generation are you talking about?
    This is for a PIC18F45K20:
    Code ( (Unknown Language)):
    1. //PWM output of 32kHz 50% duty cycle at PORTC2
    2. //Developed by: Tahmid
    3. //1st February, 2010
    4. //System clock: 4MHz
    5. //Clock source: XT Crystal
    6.  
    7. void main(void){
    8.      TRISC = 0; //PORTC OUTPUT
    9.      PORTC = 0;
    10.      PR2 = 30; //~32kHz
    11.      CCPR1L = 15; //Duty cycle 50%
    12.      CCP1CON = 0x0C; //CCP1CON = 00001100, Single output, Active High
    13.      T2CON = 4; //TMR2 on, prescale = 0
    14.      while (1);
    15. }
    http://www.edaboard.com/ftopic379285.html

    Hope it helps.
    Tahmid.
     
Loading...