Using the PWM command or CCP?


+ Reply to Thread
Results 1 to 11 of 11

Thread: Using the PWM command or CCP?1497 days old

  1. #1
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    116
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    3.08 GB

    0 Not allowed!

    Default Using the PWM command or CCP?

    Hello everyone,

    It is the first time that I have to do a project with PWM, and looking at the Proton Basic manual for using the PWM can do this in two ways.
    The 1st is using the PWM command and the other by Timer and CCP1.
    I deduced that one is the other software and hardware but which is the best or their differences.
    In the project I have to control a DC motor and I need to control the speed and running up front and back for that I have to use two outputs of the pic but not both.
    The Micro will be connected to a driver who attacks the Mosfets power, the driver has two PWM inputs to control the H bridge (March in front and back) will be connected
    to these two outputs of the pic.
    But the difference between using the PWM command and use the CCP1 or CCP2, perform the same function !!!.
    There is also the question there micros with CCP or ECCP.
    I wanted to use the PIC16F628A I have a few, and to use them, in their datasheet PIC has only one CCP (in case it was better to use it),
    I wonder if I can use puertosB PIC to send the PWM pulse anytime change the direction in Example driver:

    PWM PORTB.0, 130.255 'Forward
    PWM PORTB.1, 130.255 ' Back

    Or I have to use the CCP1 / CCP2 having to change the Micro with two CCP or ECCP.

    Thank you.

Attention
×

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,938
    Thumbs Up
    Received: 25
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Sounds like a good project for a 16F690 or similar with a ECCP Module.
    Set up the timer to desired timebase to achieve the required frequency, set up duty cycle to be variable or fixed, then use the Pulse Steering (PSTRCON Reg) to choose which pin to output the PWM.



    Here is some code for a L6203 (I think) The PWM is on P1A and P1B
    0 = PWM Off. 1 = PWM On
    P1A = PSTRCON.0
    P1B - PSTRCON.1

    P1A = 0 & P1B = 0 : Motor Off
    P1A = 0 & P1B = 1 : Forward
    P1A = 1 & P1B = 0 : Reverse
    P1A = 1 & P1B = 1 : Brake


    Device = 16F690
    Xtal 8
    All_Digital = TRUE
    Config FCMEN_OFF, IESO_OFF, BOR_ON, CPD_OFF, CP_OFF, MCLRE_OFF, PWRTE_OFF, WDT_OFF, INTRC_OSC_NOCLKOUT

    OSCCON.4 = 1
    OSCCON.5 = 1
    OSCCON.6 = 1
    Clear PORTA
    Clear PORTB
    Clear PORTC

    OPTION_REG = 0
    PortB_Pullups FALSE
    'I/O
    TRISA = 111111 '\
    TRISB = 000000 '| Set up the I/O
    TRISC = 000000 '/

    ADCON0 = 0 'A/D Module OFF
    ANSEL = 000001 'AD on RA0, rest digital
    ANSELH = 000000
    Adin_Res = 10 ' 10-bit ADC result required
    Adin_Tad = FRC ' RC OSC chosen
    Adin_Stime = 50 ' Allow 50us sample time

    CM1CON0 = 0 'Comparator 1 OFF
    CM2CON0 = 0 'Comparator 2 OFF

    WPUA.3 = 1 'PortA.3 pullup enabled for onboard button

    'SET UP CCP2 FOR PWM OUTPUT TO L6203
    '-----------------------------------
    T2CON = 000100 'Postscale: 1:1, Timer2=On, Prescale = 1:1
    PR2 = 110 'Frequency: 20 KHz '
    CCP1CON = 001100 'ECCP2 Module set for Pulse Steering
    PSTRCON = 000000
    CCPR1L = 0

    Dim DUTY As Word
    Dim I As Byte

    For I = 0 To 5
    Toggle PORTC.0
    DelayMS 100
    Next I

    LOOP:
    PSTRCON = 000010 '10 = pwm on rc4
    For DUTY = 0 To 80 Step 2
    CCPR1L = DUTY
    Toggle PORTC.0
    DelayMS 10
    Next DUTY

    DelayMS 400

    For DUTY = 80 To 0 Step -2
    CCPR1L = DUTY
    Toggle PORTC.0
    DelayMS 10 '3 is ok with just head, but needs to be larger with glass
    Next DUTY

    CCPR1L = 0
    DelayMS 400

    'reverse direction

    PSTRCON = 000001
    For DUTY = 0 To 80 Step 2
    CCPR1L = DUTY
    Toggle PORTC.0
    DelayMS 10
    Next DUTY

    DelayMS 390

    For DUTY = 80 To 0 Step -2
    CCPR1L = DUTY
    Toggle PORTC.0
    DelayMS 10
    Next DUTY

    CCPR1L = 0
    DelayMS 400

    GoTo LOOP
    Last edited by pic-ignorant; 3rd November 2015 at 21:29.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    116
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    3.08 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Forgive my ignorance,

    But is 16F690 has only one output RC5=CCP1, with this Micro can manage other outputs of Micro,
    because I Need two ouputs with PWM, these will not go at once..
    On page 13 of the Datasheet, I see this: CCP1 / P1A P1B P1C P1D, does that mean I can have 4 PWM outputs Or I have to choose another Micro have CCP1 and CCP2.

    THX.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    688
    Thumbs Up
    Received: 91
    Given: 2
    Total Downloaded
    4.62 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    I see the "PULSE STEERING MODE", all outputs are at a same time. Then you have to change PIC or write yourself two PWM software. I remember that Tim and Les have written something on this subject. It should be in the wiki or in Files.
    Alberto
    73's de Alberto ea3agv

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Prolific Poster pic-ignorant's Avatar
    Join Date
    Oct 2007
    Posts
    2,938
    Thumbs Up
    Received: 25
    Given: 31
    Total Downloaded
    926.61 MB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    The 16f690 has an ECCP module. therefore it can output PWM on any one or more of the pins allocated to P1A,P1B,P1C,P1D or a combination at the same time.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    116
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    3.08 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Hello all,


    Now that I can put me with PWM code I have other questions.
    I would like to know that I have to use crystal in the Micro, which I use is the PIC 18F26K22, to make a PWM commands HPWM Proton.


    Sintax:
    HPWM Channel, dutyCycle, Frequency


    I do not understand it is that I have seen PWM at 20KHz with crystals 8 and 16Mhz (not the HPWM command).
    in the pages of the manual Proton pág.235 puts the various crystals to be put to the micro
    Frequency and make a minimum 2.442KHz do I have to use a 40MHz crystal.
    How is it possible .... I understand nothing.!!


    As I can calculate ...


    THX greetings.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    If I understand your question: 2.442KHz is the MINIMUM frequency that you can get with a 40 meg clock.
    It means that with a 40 meg clock, that is the lowest frequency that HPWM can produce. You can get many frequencies ABOVE 2.442KHz with a 40 meg clock.

    Charlie

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Prolific Poster John Drew's Avatar
    Join Date
    Feb 2002
    Posts
    2,798
    Thumbs Up
    Received: 87
    Given: 34
    Total Downloaded
    4.53 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Mentclear, I'm not sure what your question is.Are you clear that the Xtal= at the front of a program is not the same as a quartz crystal in hardware. For example to get a 40Mhz clock you might use a 10MHz crystal and set the PLL on to give 4*10=40 clock speed and use Xtal=40 to tell the compiler it should use these numbers in its internal calculations.
    John

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    116
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    3.08 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Hello all,

    Well I am sorry , PWM This is the first time. it's complicated.
    The question is how to know, what is the best frequency for a Brushed DC motor , It is works: 36V, 35.5A and 3000RPM.
    As it calculated?

    IF 1 RPM = 0.016 666 666 667 1/second

    Freq= 0.016666666667 * 3000RPM=50Hz
    or
    Freq= 3000RPM/60s=50Hhz

    3000 RPM = 50Hhz

    To be able to control the motor correctly How often should I apply for the PWM 50Hhz or other upper> 20Khz and why?

    Code Example (mini):

    • Device = 18F26K22
      Xtal = 20
      Declare CCP2_Pin = PORTB.3

      HPWM 2,127,50 ' = 50Hz
      'or
      HPWM 2,127,20000 ' = 20Khz


    THX.
    Last edited by Mentcleer; 12th February 2016 at 10:46. Reason: bad organization.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Prolific Poster hadv215's Avatar
    Join Date
    Sep 2009
    Posts
    1,135
    Thumbs Up
    Received: 66
    Given: 26
    Total Downloaded
    3.31 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    HPWM uses the hardware module, so as soon as your program hits that instruction the device will start generating the pulse.
    If this has to go on forever, you'll only need one HPWM.
    You'll need an extra HPWM every time you want to change the channel, duty cycle or frequency.

    In the datasheet you can find which frequencies are possible given your device and the oscillator frequency (XTAL)

    Regards
    Harm

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Member Mentcleer's Avatar
    Join Date
    Aug 2014
    Posts
    116
    Thumbs Up
    Received: 2
    Given: 0
    Total Downloaded
    3.08 GB

    0 Not allowed!

    Default Re: Using the PWM command or CCP?

    Hi,

    Here again,

    when I came components made a circuit on the protoboard with Mosfet FDC855N (logic level) and led out an led (the led simulates an engine) and resistor (See Figure above).

    I know it's not a suitable circuit for an engine, just a simulation.

    when use the PWM command works perfectly, the LED lights up gradually until it begins again.

    When use the HPWM command not works, the led always is on, does not turn slowly.
    Here is the code, I thought it was easier to use the HPWM command.

    Code:
    Code:
    Device = 18F26K22               ' Chosen PIC micro controller 28 PINS
    Declare Xtal = 16               ' Chosen working frequency
    
    
    '>>>Fuse configuration<<<
    
    
    Declare Reminders Off
    Config_Start
     FOSC = HSMP 'HSMP'HSHP  'INTIO67   'HSMP	;HS oscillator (medium power 4-16 MHz)
     PLLCFG = off 'On	 ;Oscillator multipied by 4
     PRICLKEN = On   ;Primary clock enabled
     FCMEN = On'OFF	 ;Fail-Safe Clock Monitor disabled
     IESO = On 'OFF	     ;Oscillator Switchover mode disabled
     PWRTEN = On	 ;Power up timer enabled
     BOREN = OFF     ;Brown-out Reset disabled in hardware and software
     BORV = 190      ;VBOR set to 1.90 V nominal
     WDTEN = OFF     ;Watch dog timer is always disabled. SWDTEN has no effect.
     WDTPS = 32768   ;1:32768
     CCP2MX = PORTC1 ;CCP2 input/output is multiplexed with RC1
     PBADEN = OFF	 ;PORTB<5:0> pins are configured as digital I/O on Reset
     CCP3MX = PORTC6 ;P3A/CCP3 input/output is mulitplexed with RC6
     HFOFST = On     ;HFINTOSC output and ready status are not delayed by the oscillator stable status
     T3CMX = PORTB5  ;T3CKI is on RB5
     P2BMX = PORTC0  ;P2B is on RC0
     MCLRE = INTMCLR ;MCLR pin enabled, RE3 input pin disabled (INTMCLR =Disable)  EXTMCLR =Enabled
     STVREN = On     ;Stack full/underflow will cause Reset
     LVP = OFF  	 ;Single-Supply ICSP disabled
     XINST = OFF     ;Instruction seextension and Indexed Addressing mode disabled (Legacy mode)
     Debug = OFF	 ;Disabled
     Cp0 = OFF	     ;Block 0 (000800-003FFFh) not code-protected
     CP1 = OFF	     ;Block 1 (004000-007FFFh) not code-protected
     CP2 = OFF       ;Block 2 (008000-00BFFFh) not code-protected
     CP3 = OFF	     ;Block 3 (00C000-00FFFFh) not code-protected
     CPB = OFF	     ;Boot block (000000-0007FFh) not code-protected
     CPD = OFF	     ;Data EEPROM not code-protected
     WRT0 = OFF	     ;Block 0 (000800-003FFFh) not write-protected
     WRT1 = OFF	     ;Block 1 (004000-007FFFh) not write-protected
     WRT2 = OFF	     ;Block 2 (008000-00BFFFh) not write-protected
     WRT3 = OFF	     ;Block 3 (00C000-00FFFFh) not write-protected
     WRTC = OFF	     ;Configuration registers (300000-3000FFh) not write-protected
     WRTB = OFF	     ;Boot Block (000000-0007FFh) not write-protected
     WRTD = OFF	     ;Data EEPROM not write-protected
     EBTR0 = OFF	 ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
     EBTR1 = OFF	 ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
     EBTR2 = OFF	 ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
     EBTR3 = OFF	 ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
     EBTRB = OFF	 ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End
    
    
    Declare Reminders On
    
    
    Declare Optimiser_Level  = 2
    Declare Dead_Code_Remove = 1
    
    
    Declare CCP3_Pin PORTB.5
    Dim J As Byte                 'Dutycycle
    
    
     TRISB=0                     'PortB ALL Outs
     ANSELB = 0                  'PORTB All Digital
    
    
    Symbol PWM_Led = PORTB.5     'CCP3 PIN26
    DelayMS 100                  'Stabilize PIC
         
    J=0                        'Duty =0 
         
    Main:
     
     For J=0 To 255            'Dutycycle 0 to 255
      'pwm PWM_Led,J,255       'WORK OK
      HPWM 3,J,2000            'NOT WORK  2Hhz
      DelayMS 1000             'Sequence Delay 
     Next
    
    
    GoTo Main
    Circuit Figure:
    Click image for larger version

Name:	H_PWM.jpg
Views:	6
Size:	87.2 KB
ID:	2931

    THX.

  • Attention
    ×

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. PWM to Analog Out using CCP PWM Mode
      By fgcity in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 2nd September 2015, 13:32
    2. Replies: 8
      Last Post: 2nd August 2013, 12:57
    3. Need some help with ccp module
      By C_Moore in forum The Lounge
      Replies: 1
      Last Post: 29th July 2011, 09:53
    4. problem with 2 CCP inputs
      By RGV250 in forum Proton Plus Compiler v3
      Replies: 5
      Last Post: 21st June 2009, 15:51
    5. [SOLVED !] Need a chip w/ 2 CCP modules and 2 PWM timers
      By HelpMe! in forum Proton Plus Compiler v3
      Replies: 12
      Last Post: 8th October 2007, 20:25

    Members who have read this thread since 8th December 2019, 01:13 : 0

    Actions :  (Set Date)  (Clear Date)

    You do not have permission to view the list of names.

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts