Hot!PIC18F PWM programming

Author
Colerock87
New Member
  • Total Posts : 1
  • Reward points : 0
  • Joined: 2018/10/15 12:40:18
  • Location: 0
  • Status: offline
2018/11/03 04:37:11 (permalink)
0

PIC18F PWM programming

Hi, I am pretty new to microchip and PIC it self and I am learning the old assembly machine language programming first.
 
I am using a 2010 PICDEM 2 PLUS demo board with an PIC18F452 MCU and 4Mhz Oscillator. I have about 4 months experience on programming this PIC to make different functions. 
 
What I am trying to achieve this time is the following:
 
Create a PWM program that initializes the system on the PICDEM 2 PLUS demo board
to a frequency of 2 kHz and duty cycle of 50%.
 
So basicly, When switch S2 (RA4) is pressed, the duty cycle should be changed by turning on the potentiometer
(RA0).
When switch S3 (RB0) is pressed, it should change the frequency by turning on the same potentiometer.
 
I belive that to get a frequency of 2 kHz, appropriate initial values are PR2 = 128, CCPR1L = 63 and TMR2PreScale = 4 have to be used.
 
I basicly need a assembly low level code for this so that I can learn and study it more. And that I can use it on the PICDEM 2 PLUS board. Later I will connect an oscilloscope to measure and look how dyty cycle and the frequency changes.
 
Can anyone who is expert on this make or help me make a code?
#1

3 Replies Related Threads

    MBedder
    Circuit breaker
    • Total Posts : 6714
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: PIC18F PWM programming 2018/11/03 05:01:27 (permalink)
    +2 (2)
    Colerock87Can anyone who is expert on this make or help me make a code?
    Certainly. $9995 - and the code is yours in an hour after the money transfer.


    #2
    katela
    Super Member
    • Total Posts : 1186
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: PIC18F PWM programming 2018/11/03 10:46:52 (permalink)
    +2 (2)
    Did you study your datasheet?
    Ask questions with your code and you'll get support. It's unlikely anybody will write the whole code for you.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #3
    mpgmike
    Senior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: PIC18F PWM programming 2018/11/05 08:11:49 (permalink)
    +1 (1)
    Here are 2 options:
    T2PRE = 4, PR2 = 124, CCPRL = 250
    T2PRE = 16, PR2 = 30, CCPRL = 62
     
    Both yield 2 kHz @ 50% DC%.  1:4 T2PRE requires CCPRH as for 100% DC, CCPRx = 500.  1:16 T2PRE maxes out at 125 for 100% DC.
     
    If the 2 kHz isn't that critical, you may wish to use a frequency that allows the DC% to range from 0 to 255 so your pot ADC value can be directly copied to your CCPRL register.  4 kHz with a 1:4 T2PRE gives you 0 to 250, 3.9 kHz gives 0 to 256 CCPRL range.
    #4
    Jump to:
    © 2019 APG vNext Commercial Version 4.5