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.
-
AuthorPosts
-
September 29, 2017 at 6:40 am #4693
S Ganesh
ParticipantHi 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 #14675Ashutosh Bhatt
Participantwhy are you writing PWM_H_ ?
it should be PWM_H only
February 16, 2019 at 6:43 am #15019Saatwik
Participantif 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.
-
AuthorPosts
- You must be logged in to reply to this topic.