EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Topics / capture PWM

capture PWM

|

Microcontroller › PIC › capture PWM

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 9 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • October 27, 2014 at 11:22 am #3308
    ilia
    Participant

    capture code for pwm not working please help

    #pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF                       // CONFIG1H
    #pragma config WDTEN = OFF, WDTPS = 2048                                     // CONFIG2H
    #pragma config STVREN = ON, LVP = OFF, XINST = OFF                          // CONFIG4L
    #pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF                   // CONFIG5L
    #pragma config CPB = OFF, CPD = OFF                                         // CONFIG5H
    #pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF               // CONFIG6L
    #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF                           // CONFIG6H
    #pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF           // CONFIG7L
    #pragma config EBTRB = OFF , PBADEN = OFF ,MCLRE = EXTMCLR , CCP2MX = PORTC1
    #pragma config P2BMX  = PORTD2 
    #include <p18f46k22.h>
    #include <stdlib.h>
    #include <stdio.h>
    // *************** Initialize Capture mode for PWM input ************************* 
     void main (void)
    {
    long uPWM_Low;
    long uPWM_Hi;
    long bRisingEdge;
    long uPWM;
    ANSELB=0b0;
    ANSELC=0b0;
    TRISC=0b00000010;
    TRISB=0b11110000;
    //trigger on rising edge 
    uPWM=0;
    bRisingEdge=1;
    PORTBbits.RB1=0b0;
    PORTBbits.RB3=0b0;
    PORTBbits.RB0=0b0;
    PORTBbits.RB2=0b0;
    T1CON= 0b00000111;
    CCP1CON=0b0000101; 
    CCPTMRS0bits.C1TSEL0 = 0; 
    CCPTMRS0bits.C1TSEL1 = 0; 
    while(1)
    {
    if (PIR1bits.CCP1IF==0b1) 
      { 
       // get PWM capture reading 
       uPWM_Low = CCPR1L; 
       uPWM_Hi = CCPR1H;
       uPWM = CCPR1H*256UL|CCPR1L; 
       if (bRisingEdge==1) 
       { 
        // Set trigger on falling edge 
        CCP1CON = 0b00000100; 
        bRisingEdge = 0;
        PIR1bits.CCP1IF=0b0; 
       } 
       else 
       { 
        // Set trigger on rising edge 
        CCP1CON = 0b00000101; 
        bRisingEdge = 1;
        PIR1bits.CCP1IF=0b0; 
       }    
    if (uPWM_Hi>0)
    {
    PORTBbits.RB3=0b1;
    PORTBbits.RB2=0b1;
    PORTBbits.RB1=0b1;
    PORTBbits.RB0=0b1;
    }
    }
    }
    }
    October 28, 2014 at 4:36 am #12325
    AJISH ALFRED
    Participant

    Please explain what is going wrong as you observed.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Seeking Help to compile code August 17, 2022
  • Nokia 5110 HW in Oshonsoft August 17, 2022
  • Digital Display Information August 17, 2022
  • 2nd pcb design program? August 17, 2022
  • Door exit button August 17, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools