
Thread: HELP PLEASE - PWM on Pic18F47J53 !!! – 12 days old
-
6th February 2019, 10:18 #1
0HELP PLEASE - PWM on Pic18F47J53 !!!
Hi All
Yesterday I posted about the HPWM setup on the 18F47J53 Device and it is clear that the Proton Compiler only Supports Two Channels on HPWM.
OK my question is How do I setup the TWO Channels for CCP1 & CCP2 ? The issue is that on the 18F47J53 it Has Seven CCP's (CCP4 -CCP10), I understand
from Les's Post that the compiler only supports two (CCP1 & CCP2), I have tried numerous ways of setting this but, to no avail.
How do I get CCP4 to be seen as CCP1 and the same goes for CCP5 to be seen as CCP2 ? Remember they START at CCP4 and Go To CCP10, I have looked in
the PPI.inc file and it looks correct, CCP4 is addressed to Channel 1 all the way to CCP10 which is addressed as Channel 7.
I have connected LED's to PORTB.4 (CCP4) & PORTB.5 (CCP5) and ensured they are working by simply switching them on and off but, I cannot get them to
work with HPWM. Their Must be a way of getting them to be seen as CCP1 & CCP2.
The Problem is I have to use HPWM on the above two pins as I need to control a motors speed & Direction on them! I CANNOT Change this Now!
Any Help Is Very much appreciated.
Kind Regards
Craig
I have tried the following but, to No Avail:
Device = 18F47J53
Declare Xtal = 48 ' Using an external XTAL 16Mhz Set @ HSPLL
TRISB = %00000000
Declare HPWM1_Pin = PORTB.4 ' CCP4
Declare HPWM2_Pin = PORTB.5 ' CCP5
OR I Tried CCP1/2 Instead
Declare CCP1_Pin = PORTB.4 ' CCP4
Declare CCP2_Pin = PORTB.5 ' CCP5
'===================================
TestH:
HPWM 1,200,20000 ' CCP4 PORTB.4 LED ON
HPWM 2,250,20000 ' CCP5 PORTB.5 LED ON
DelayMS 500 ' ON TIME For LED's
HPWM 1,0,0 ' CCP4 PORTB.4 LED OFF
HPWM 2,0,0 ' CCP5 PORTB.5 LED OFF
Return
'===================================
-
6th February 2019, 12:22 #2
- Join Date
- Feb 2002
- Posts
- 3,119
- Total Downloaded
- 1.53 GB
Thumbs Up Received: 356
Given: 129
0Re: HELP PLEASE - PWM on Pic18F47J53 !!!
You've chosen one of the very, very early devices that had PPS on it, and the way Microchip implemented it then, means the compiler cannot auto setup for it easily, so I put it to one side and will do that mechanism ASAP, because it is logistically time consuming for all the early J types with PPS, because they are all, bloody, different!.
The problem is that the RPx pins do not match the Port Pins logically. For example RP0 is PORTA.0, RP1 is PORTA.1, but RP2 is not PORTA .2, but PORTA.5 ! The same goes for all the other RP pins. The later K types and the enhanced 14-bit core types have a logic behind the PPS pins, so a simple calculation can be done to set which pin or a port is required. But even the later devices have 3 different ways of setting up PPS, so Microchip have done it again, and again, and again. :-(
When working on, especially the dreadful J, devices, it is important to read the datasheet for them, and for this, it is section 10.7 in the datasheet.
I've created an include file to manipulate PPS for the 18F47J53 device, and the code is here. The values are taken from the datasheet section 10.7:
Code:$ifndef _PPS_Inc_ $define _PPS_Inc_ ' ' /\\\\\\\\\ ' /\\\///////\\\ ' \/\\\ \/\\\ /\\\ /\\\ ' \/\\\\\\\\\\\/ /\\\\\ /\\\\\\\\\\ /\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\\\ /\\\\\\\\\ ' \/\\\//////\\\ /\\\///\\\ \/\\\////// /\\\/////\\\ \////\\\//// \////\\\//// \////////\\\ ' \/\\\ \//\\\ /\\\ \//\\\ \/\\\\\\\\\\ /\\\\\\\\\\\ \/\\\ \/\\\ /\\\\\\\\\\ ' \/\\\ \//\\\ \//\\\ /\\\ \////////\\\ \//\\/////// \/\\\ /\\ \/\\\ /\\ /\\\/////\\\ ' \/\\\ \//\\\ \///\\\\\/ /\\\\\\\\\\ \//\\\\\\\\\\ \//\\\\\ \//\\\\\ \//\\\\\\\\/\\ ' \/// \/// \///// \////////// \////////// \///// \///// \////////\// ' Let's find out together what makes a PIC Tick! ' ' Peripheral Pin Select Setup Routines for PIC18F47J53 device ' $ifndef _18F47J53_ $error "This PPS file is for a PIC18F47J53 device only" $endif ' ' Peripheral pin Input destinations ' $define PPS_iINT1 _RPINR1 ' External Interrupt 1 $define PPS_iINT2 _RPINR2 ' External Interrupt 2 $define PPS_iINT3 _RPINR3 ' External Interrupt 3 $define PPS_iT0CKI _RPINR4 ' Timer0 External Clock Input $define PPS_iT3CKI _RPINR6 ' Timer3 External Clock Input $define PPS_iT5CKI _RPINR15 ' Timer5 External Clock Input $define PPS_iCCP1 _RPINR7 ' Input Capture 1 CCP1 $define PPS_iCCP2 _RPINR8 ' Input Capture 2 $define PPS_iCCP3 _RPINR9 ' Input Capture 3 $define PPS_iT1G _RPINR12 ' Timer1 Gate Input $define PPS_iT3G _RPINR13 ' Timer3 Gate Input $define PPS_iT5G _RPINR14 ' Timer5 Gate Input $define PPS_iRX2 _RPINR16 ' EUSART2 Asynchronous Receive/Synchronous Receive $define PPS_iCK2 _RPINR17 ' EUSART2 Asynchronous Clock Input $define PPS_iSDI2 _RPINR21 ' SPI2 Data Input $define PPS_iSCK2IN _RPINR22 ' SPI2 Clock Input $define PPS_iSS2IN _RPINR23 ' SPI2 Slave Select Input $define PPS_iFLT0 _RPINR24 ' PWM Fault Input ' ' Peripheral Pin Select Output sources ' $define PPS_oNULL 0 ' Null $define PPS_oC1OUT 1 ' Comparator 1 Output $define PPS_oC2OUT 2 ' Comparator 2 Output $define PPS_oC3OUT 3 ' Comparator 3 Output $define PPS_oTX2 6 ' EUSART2 Asynchronous Transmit/Asynchronous Clock Output $define PPS_oDT2 7 ' EUSART2 Synchronous Transmit $define PPS_oSDO2 10 ' SPI2 Data Output $define PPS_oSCK2 11 ' SPI2 Clock Output $define PPS_oSSDMA 12 ' SPI DMA Slave Select $define PPS_oULPOUT 13 ' Ultra Low-Power Wake-up Event $define PPS_oCCP1 14 ' ECCP1 Compare or PWM Output Channel A $define PPS_oP1B 15 ' ECCP1 Enhanced PWM Output, Channel B $define PPS_oP1C 16 ' ECCP1 Enhanced PWM Output, Channel C $define PPS_oP1D 17 ' ECCP1 Enhanced PWM Output, Channel D $define PPS_oCCP2 18 ' ECCP2 Compare or PWM Output $define PPS_oP2B 19 ' ECCP2 Enhanced PWM Output, Channel B $define PPS_oP2C 20 ' ECCP2 Enhanced PWM Output, Channel C $define PPS_oP2D 21 ' ECCP2 Enhanced PWM Output, Channel D $define PPS_oCCP3 22 ' ECCP3 Compare or PWM Output $define PPS_oP3B 23 ' ECCP3 Enhanced PWM Output, Channel B $define PPS_oP3C 24 ' ECCP3 Enhanced PWM Output, Channel C $define PPS_oP3D 25 ' ECCP3 Enhanced PWM Output, Channel D ' ' Peripheral Pin Select sources and destinations ' $define RP0 0 $define RP1 1 $define RP2 2 $define RP3 3 $define RP4 4 $define RP5 5 $define RP6 6 $define RP7 7 $define RP8 8 $define RP9 9 $define RP10 10 $define RP11 11 $define RP12 12 $define RP13 13 $define RP14 14 $define RP15 15 $define RP16 16 $define RP17 17 $define RP18 18 $define RP19 19 $define RP20 20 $define RP21 21 $define RP22 22 '----------------------------------------------------------------------------------------- ' Peripheral Pin Select Input Configuration ' Input : pPeripheral holds the peripheral to set the PPS for ' : pPinR holds the RP number for the peripheral pin ' Notes : None ' $define PPS_input(pPeripheral, pPinR) ' WREG = pPinR ' Movwf (pPeripheral) '----------------------------------------------------------------------------------------- ' Peripheral Pin Select Output Configuration ' Input : pPeripheral holds the peripheral to set the PPS for ' : pPinR holds the RP number for the peripheral pin ' Notes : None ' $define PPS_Output(pPeripheral, pPinR) ' WREG = pPeripheral ' Movwf (RPOR#V(pPinR)) '----------------------------------------------------------------------------------------- ' Unlock Peripheral Pin Select Registers ' $define PPS_Open() ' Movlb (EECON2 >> 8) ' EECON2 = $55 ' EECON2 = $AA ' Clear PPSCONbits_IOLOCK '----------------------------------------------------------------------------------------- ' Lock Peripheral Pin Select Registers ' $define PPS_Close() ' Movlb (EECON2 >> 8) ' EECON2 = $55 ' EECON2 = $AA ' Set PPSCONbits_IOLOCK $endif ' _PPS_Inc_
The code below is a demo of the above routines being used:
Code:Device = 18F47J53 Declare Xtal = 32 Declare CCP1_Pin = PORTC.0 Declare CCP2_Pin = PORTC.1 Include "PPS_18F47J53.inc" ' Load the PPS routines into the program PPS_Open() ' Unlock PPS registers PPS_Output(PPS_oCCP1, RP11) ' CCP1 output assigned to RP11 pin (RC0) PPS_Output(PPS_oCCP2, RP12) ' CCP2 output assigned to RP12 pin (RC1) PPS_Close() ' Lock PPS Registers HPWM 1, 127, 3000 HPWM 2, 127, 3000 Stop
Last edited by Les; 6th February 2019 at 12:56.
For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files
-
6th February 2019, 12:40 #3
0Re: HELP PLEASE - PWM on Pic18F47J53 !!!
THANK So Much Les for all your Help and Kindness You are an absolute lifesaver.
Kind Regards
Craig
-
6th February 2019, 19:51 #4
0Re: HELP PLEASE - PWM on Pic18F47J53 !!!
THANK YOU Les!!
I spent some time studying the Data sheet and looking at your beautifully written code and It now makes sense
and I have my motor points working. Thanks for your very quick response and Help, I am very grateful.
Kind Regards
Craig
-
6th February 2019, 20:08 #5
- Join Date
- Feb 2002
- Posts
- 3,119
- Total Downloaded
- 1.53 GB
Thumbs Up Received: 356
Given: 129
0Re: HELP PLEASE - PWM on Pic18F47J53 !!!
You are very welcome Craig.
I have always prided myself with the clarity of my code, and is something I have taken time to master. Even though it takes extra time doing the comments, it makes the code easier to understand, both for myself if I come back to the code after a few months or years, and to others who are using the code.
Format and Comments are a very important part of programming, but is, unfortunately, a dying art. LOL I've seen many, many pieces of C and C++ code, that are meant to be for others to learn from, but they have zero comments, or comments that are too obscure, so the code has to be studied over and over again, just to see what is happening. Or their format is so jumbled that the pattern of the code disappears.
I'm also a great believer in the format of code, so indents and spaces etc are important, because I can see the pattern of code before I study it, and the pattern itself tells me a lot of what the code is doing.
Glad you got it working, but next time, keep away from the J types. LOL I made that mistake as well a few years ago, and they were dreadful. The newer K types are really nice devices.For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files
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.
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.
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.
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.
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
-
PWM to Analog Out using CCP PWM Mode
By fgcity in forum Proton Plus Compiler v3Replies: 1Last Post: 2nd September 2015, 13:32 -
PWM, dithered PWM and Tmr1 as a (variable bit) PWM source.
By david in forum The LoungeReplies: 8Last Post: 2nd August 2013, 12:57 -
PIC18F47J53 and PIC18F27J53
By Cranes in forum Wish List / Product FeedbackReplies: 0Last Post: 17th February 2012, 12:36 -
[SOLVED !] Pwm
By naseerak in forum Proton Plus Compiler v3Replies: 11Last Post: 25th October 2008, 08:54 -
Need PWM help...
By cgriffin in forum Proton Plus Compiler v3Replies: 1Last Post: 30th August 2007, 05:27
Members who have read this thread since 18th February 2019, 01:33 : 0
Actions : (Set Date) (Clear Date)
You do not have permission to view the list of names.
Proton Compiler Updates
Full install of 8-bit Proton and Proton24 Download the full compiler...
1st January 1970, 01:00