Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pwm generation using pic18f452

Status
Not open for further replies.

venkatesh123

Newbie level 3
Joined
Mar 15, 2010
Messages
4
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,283
Location
pilani
Activity points
1,312
hi
plz help me out to solve this problem.i need a variable duty cycle and frequency of 1hz to 200 hz using pic18f452 in assembly,but don't know how to do this.

so pls help me out
 

hi,
the code given uses timer2 which is 8 bit timer and it can generate frequency of 244hz(min.) which doesn't satisfy my requirement
 
  • Like
Reactions: touhamyz

    V

    Points: 2
    Helpful Answer Positive Rating

    touhamyz

    Points: 2
    Helpful Answer Positive Rating
Hi,

Well if the hardware pwm module does not meet your needs you will have to use a software pwm.

The problem with the software pwm is that it does tie up your processing power a lot.

You will have to work out your delays for the given frequencies duty cycle and period and then code delays to produce the output pulses.

You can do it simply by using standard delay loops or use the timers and interrupts if you need to be doing a lot of other things.

Alternatively search for some fancy program code that uses some alogrithims to create the pulses, I don'tknow of any but sure there will be some around - try PicList or places like you tube where they like using pwm on led displays etc
 

hi
well thanx for ur help,i have an idea but i don't whether it wud work or not. i am using timer 1 as counter load the count according to 1Hz signal and when the count is matched it wud generate an inerrupt,during that time with timer2 load the count of duty cycle using ccp.
well i am not sure enough whether it wud work or not,so pls guide me
 

hi,
i went to the datasheet u provided,but the problem in that is it has an analog input from A/D and using it the pwm is controlled.
but in my case i have to generate the varying pwm from 1hz to 200 hz using pic18f452
 

Hi do you manage to get source code to generate PWM using PIC18F452?
 

Hi,
Here is a sample code:
Code:
//Program to generate 40kHz output at RC2(CCP1) pin
//Microcontroller: Microchip PIC18452
//Language: C
//Compiler: mikroC v8.20
//Programmer: Tahmid

void main (void){
     TRISC = 0;
     PORTC = 0;
     ADCON1 = 7;
     T2CON = 0;
     TMR2 = 0;
     PWM1_Init(40000); //40kHz
//The value in brackets in PMW1_Init represents the frequency in Hz
     PWM1_Change_Duty(128); //50% duty cycle
// Choose Duty cycle as such:
// PWM_Change_Duty(x);
// x = ( (Duty Cycle in %) / 100) * 255
     PWM1_Start(); //Start PWM
     while (1){ //Loop forever
// Whatever else might be needed to be done while PWM is running
     }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top