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
  • Advertise
You are here: Home / Topics / Error in my PWM library

Error in my PWM library

|

Microcontroller › AVR › Error in my PWM library

  • This topic has 2 replies, 3 voices, and was last updated 6 years, 11 months ago by Saatwik.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • September 29, 2017 at 6:40 am #4693
    S Ganesh
    Participant

    Hi I am creating a PWM library in c++ to use in my project. I have started working on it below is part of my code it is not complete yet. I have writing a bit by bit code and building it to find errors and I find some error. So I stopped. Even though I had defined right parameters it is giving error. It should preprocess first #if and assign TCC0A with 0x80. But it skipping #if, #elif and last #else is execuing. Please help me to correct given code.

    IDE: Atmel Studio 7.0

    MCU: ATmega328p

    Code:

    /************************************************************
                                         PWM.h file
    ************************************************************/
     
    #ifndef PWM_H_
    #define PWM_H_
     
    //PWM outputs
    #define OC0A 1
    #define OC0B 2
     
    //PWM modes
    #define NINV 0b10000000      //Non-inverting Mode
    #define INV  0b11000000      //Inverting Mode
     
    #include <avr/io.h>
     
    class PWM
    { 
        public:
            void Initialize(unsigned char PWMoutputpin,  unsigned char PWMmode)
        {
               TCCR0A = 0x00; TCCR0B = 0x00;
           #if ((PWMoutputpin == OC0A) && (PWMmode == NINV))
                 TCCR0A |= NINV;
      
       #elif ((PWMoutputpin == OC0A) && (PWMmode == INV))
              TCCR0A |= INV;
     
        #elif ((PWMoutputpin == OC0B) && (PWMmode == NINV))
                TCCR0A |= (NINV >> 2);
     
        #elif ((PWMoutputpin == OC0B) && (PWMmode == INV))
                TCCR0A |= (INV >> 2);
     
        #else
          #error PWM::Initialize() parameters not defined properly.
      #endif
       }
    };
    #endif /* PWM_H_ */
    /******************************* END **********************/
     
     
    /************************************************************
                                          main.cpp file
    ************************************************************/
    #include <avr/io.h>
    #include "PWM.h"
     
    int main(void)
    {
        PWM p;
        p.Initialize(OC0A,NINV);
        return 0;
    }
    October 19, 2017 at 1:32 pm #14675
    Ashutosh Bhatt
    Participant

    why are you writing PWM_H_   ?

    it should be PWM_H only

    February 16, 2019 at 6:43 am #15019
    Saatwik
    Participant

    if you are getting error that PWM_H_ file in not found then you should check first your library name if it is PWM.h make sure in the program it is same at the time of include.

     

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

RSS Recent Posts

  • Variable audio oscillator January 17, 2026
  • Sine wave distortion January 17, 2026
  • My Advanced Realistic Humanoid Robots Project January 17, 2026
  • Micro mouse January 17, 2026
  • flexible copper cable January 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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
  • Advertise