I am trying to use HPWM for modulating a proportional hydraulic valve to replace an existing circuit that no longer functions correctly.
I am using a 18F26K20 and I am using a code sample from the basic manual. (code sample was a 16F877A, 20)
I need to get the pulse repetition rate down to 50 Hz.
With the clocks set at 16 MHz I get the proper proportional rate at 1 kHz when I set the HPWM rate to 1
I have tried reducing the clock rate to different values but non work that make any sense below 32 MHz and 16 MHz.
Any suggestions would be of great value.
Here are the rep rates for various #chip 18F26K20 , x
x= 32 rep rate is 2Khz
x=16 rep rate is 1 kHz
x=8 rep rate jumps up to 2 kHz ????
x= 10 rep rate is 100 hz (probably an illegal setting for this chip?
'This will be the pwm modulator for porportional hydrolic valves
'PEH Oct 29 2017
'ASM Ver 0.97.01
'This program will alter the brightness of an LED using
'hardware PWM.
'Select chip model and speed
#Option Explicit
#chip 18F26K20 , 16 ;10 make slow clk, but 10 doesn't make sense ???
#config Osc = int
#config mclr=on ;reset PB enabled
'Set the CCP1 pin to output mode
DIR PORTC.2 out
Dim Bright as byte ;
'Main code
do
'Turn up brightness over 2.5 seconds
For Bright = 1 to 255
HPWM 1, 1, Bright
wait 10 ms
next
'Turn down brightness over 2.5 seconds
For Bright = 255 to 1
HPWM 1, 1, Bright
wait 10 ms
next
loop
Last edit: Paul Haug 2017-10-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Based on using v0.98.0x (I have v0.98.01 here... I will release this week).
The operating frequencies for the internal clock are 64, 32, 16, 8, 4, 2, 1, 0.5, 0.25. So, 10 would need an external oscillator.
This chip has a specific configuration for the the oscillator. Internally, with GCBASIC we call this 'IntOSCCONFormat'. So, you need v0.98.xx to support the clock correctly.
I have just tested you code and it works a treat here using the v.98.xx
Upgrade your installation please.
Is your question... what are the PWM frequencies (a range) supported at each chip frequency?
Last edit: Anobium 2017-10-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
And, if you want to check that a PWM frequency is supported by a chip frequency when using CCP/PWM.
Try the fixed mode first. This will issue an error message if the PWM frequency is NOT supported by a chip frequency.
#chip <whateventchip>, <whatever chip frequency >
#define PWM_Freq 1 'Frequency of PWM in KHz
#define PWM_Duty 50 'Duty cycle of PWM (%)
HPWMOn 1
Also, in the latest build you can test...
'Addthistoyouruserprogram.'AtestpieceoftotestwhetheryourdesiredFrequencyforchipfrequencyandPWMfrequency.'Why?IfyouchiphasnotgotbitT2CKPS2thenmaximumTimer2ClockPrescaleis16,so,wecantestifwehaveoverflowed.Thepostscaleris1-so,wearelimitedtoaspecificrangeoffreqencies.#ifndef bit(T2CKPS2) 'This tells us the the Timer2 Clock Prescale is limited to 16'USARTsettings-setuptheserialport-connectstodefaultport#define USART_BAUD_RATE 9600#define USART_TX_BLOCKINGHSerPrintCRLF2'Ifbits0and1ofT2CONaresetthenweHAVEoverflowed!!'00=Prescaleris1'01=Prescaleris4'1x=Prescaleris16'11=Overflowed!Weusethetwobitstoshowwehaveanoverflowconditionift2conand3=3thenHSerPrint"Error - Lower Chip Frequency, "HSerPrint"or raise PMW Frequency!"HSerPrintCRLFelseHSerPrint"Chip and PWM Frequency OK!"endif#endif
:-)
Last edit: Anobium 2017-10-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have upgraded to V0.98.00 as you suggested, but any thing below clock selection (internal) of 16 or 32 mhz gives strange results on the HPWM repition rate.
Your question of: Is your question... what are the PWM frequencies (a range) supported at each chip frequency?
That is my problem, I need 50Hz (or approximatly) for the hydro valves to operate correctly.
.
I will try your suggestions today with the HserPrint as a debug test.
Thanks
Last edit: Paul Haug 2017-10-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks kent_twt4,
That certianly gives me another approach since my application is closely related to RC servo control, except I need full (0-100%) pulse width control, but with some tweeking that code should work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is a set of calculators - this WILL show the range of frequencies per a selected chip freq. See the TimerCalculator for the calculator for 50 hz... it is a max chip freq of 8mhz on your chip.
The 18f26k20 has a TMR3 to play with too, so you could sync up a full scale PWM duty cycle using a TMR3 count (or overflow) + interrupt, in the TMR1 interrupt.
As Evan shows, plenty of ways to get what you need. Using the CCP special event trigger is another option.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Aparantly neither Microchip nor GCB figured that anyone would want/need to use Hardware PWM at less than 1Khz.
The 18F26K20 only allows for one possible clock source for TMR2 and that is FOSC/4. So we are stuck with that. Using the internal osc (chip MHz) we can get to 50 hz PWM only one way. That is by setting the Chip MHz to 2 and then manually setting the Timer2 Prescale to 128 and the Timer2 Period Register ( PR2) to 152
The problem with this is that changing the duty cycle on-the-fly using HPWM function will likely be glitchy as it will reset the timer period to an unwanted value. You may be able to write the CCPR1H duty register directly, bypassing the high level GCB HPWM command which always reset the timer period.
My suggestion for 50Hz PWM with GCB on your chip is to bit bang it usiing a 16 bit timer. Optionally you could get a more modern chip that supports multple clock sources to TIMER2//4/6 and that has Dedicated PWM modues.
50 Hz is a common frequency for Servo contol. If you are wanting to control a servo then please indicate so as 8- bit PWM will not give the resolution necessary for good Servo control.
Below is Example Code (Untested) that should show to get 50 hz PWM using a 18F26K20 with 2Mhz Internal Clock Source . I created a sub to set duty cycle as a percentage to eliminate to need to use HPWM to change duty cycle. Use this only if you can live with a 2 Mhz system cock.
#chip 18Ff26k20, 2
;// Add Config options as necessary
#option Explicit
Dir PORTC.1 OUT ; >>>> PWM
HPWM (1, 1, 20) ; start PWM
PR2 = 153 ; override GCB Setting
T2CON = b'11100000' ; Pre = 1:128 /Override HPWM Settings
DIM DutyVal as Byte
Do
For DutyVal = 0 to 100
SetDuty (DutyVal) ;In percentage
Wait 100 ms
Next
For DutyVal = 100 to 0 Step -1
SetDuty (DutyVal) ;In percentage
Wait 100 ms
Next
Loop
Sub SetDuty (in TMPVar1 as Byte )
'// Sets duty from 0 to 100 percent
CCPR1H = ([WORD]TMPVAR1 * 154) / 100
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
50Hz pwm would have to lower chip clock speed to get pwm resolution I found.
for a servo why not interrupt pulseout..my idea of servo is model controller actuator not servo motor.
~~~
;set up servo interrupt 50Hz
on interrupt timer1overflow Call servo
inittimer1(OSC,PS1_2)
Starttimer 1
;
sub servo ;servo interrupt
settimer 1, 25535
pulseout Servo_Pin , servoposition 10us
end sub
~~~
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many thanks, I will work on the various suggestions.
This is for a rather large hydraulic control system that uses proportional valves that look like solenoids. By scoping the working units I see the pulses are at 50Hz and duty cyle of the pulses is 0 to 100%, zero being closed and 100% being fully opened.
* 8 bit resolution will be fine, the operator uses a joy stick to control the speed of lift, drive, swing of a platform. Many safety switches and limits are used that the uProc will not control.
The software will be doing other things also, like logging temp, operating relays and indicator lights and a serial output. EDIT: Added some comment info.
Last edit: Paul Haug 2017-10-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 18F26K20 has 64K Flash and 4K SRAM. So I assume this chip was not just randomly selected, but was slelected for its large amount of memory an/or its 64MHz max speed
A newer alternative is the 18F26K40. This chip has the same memory & speed specifications but includes a wealth of new features and new perieherals.
In regards to your applcation the 18F26K40 has updated Timer2/4/6 modules that support multiple clock sources, and it also has a Reference Clock Module. This makes it relatively easy to get a 50 Hz PWM while operating the chip at up to 64Mhz.
The idea is to clock Timer 2 using the Reference Clock, then to use Timer2 as the clock source for the CCP or PWM module used for the PWM.
While GCB's PWM library does not yet support all the possible clock source combinations for HPWM, with a few extra lines of code a 50Hz is quite possible.
Below is working example code using a PIC18F27K40 that I had laying around, the only difference being is that the 18F27K40 has 128K Flash instead of 64K with the 18F26K40. Hook your scope up to PIN C.1 to see the output. Or attach an LED.
; Unofficial Example/Demo of Low Frequency (50Hz) PWM
; Uses CCP1/Timer2 & Reference Clock Modules
; William Roth
'Chip Settings.
#chip 18f27k40, 32
#config FEXTOSC = OFF, RSTOSC = HFINTOSC_64MHZ, LVP = ON
#option Explicit
#startup InitPPS, 85
' Define I2C settings
#define HI2C_BAUD_RATE 125
#define HI2C_DATA PORTC.4
#define HI2C_CLOCK PORTC.3 ;unnecessary
'Initialise I2C
Dir HI2C_DATA IN
Dir HI2C_CLOCK IN
HI2CMode Master
'''Set up LCD
#define LCD_IO 10
#define LCD_I2C_Address_1 0x7E
#define LCD_SPEED Fast
#define LCD_Backlight_On_State 1
#define LCD_Backlight_Off_State 0
CLS
InitLCD 'Just in case but probably unnecessary
DIM DutyVal as Byte ' set aside variable for duty cycle
Dir PORTC.1 OUT ; PWM out on Pin C.1 (see InitPPS Sub)
HPWM (1, 1, 0) ; Start CCP1 PWM with zero Duty (off)
'These lines override settings of HPWM library and allow 50 hz PWM
PR2 = 156 ; Override HPWM Setting of period register
CLKRCON = 0b10010110 ; Config & start Reference Clock Module
T2CLKCON = 0b00000111 ; Set timer2 Clk source as Reference Clock Out
T2CON = 0b11100000 ; Override HPWM Setting of T2 Prescale
'// Splash scren
CLS : Wait 1 S
Call SPLASH
'// Test PWM from 0 to 100 percent duty
Do
For DutyVal = 0 to 100
SetDuty (DutyVal) ;In percentage
Wait 20 ms
Next
'Wait 2 s
For DutyVal = 100 to 0 Step -1
SetDuty (DutyVal) ;In percentage
Wait 20 ms
Next
'Wait 2 S
Loop
Sub SetDuty (in TMPVar1 as Byte )
CCPR1L = 0
CCPR1H = ([WORD]TMPVAR1 * 157) / 100
End Sub
SUB SPLASH
CLS
Print "Great Cow BASIC"
Locate 1,0
Print "Ver 0.98.01"
END SUB
Sub InitPPS
'Module: CCP1
RC1PPS = 0x0005 'CCP1 > RC1
CCP1PPS = 0x0011 'RC1 > CCP1 (bi-directional)
'Module: MSSP1
RC3PPS = 0x000F 'SCL1 > RC3
SSP1CLKPPS = 0x0013 'RC3 > SCL1 (bi-directional)
RC4PPS = 0x0010 'SDA1 > RC4
SSP1DATPPS = 0x0014 'RC4 > SDA1 (bi-directional)
End Sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Many thanks William. I used the 18F26K20 because I had a tube full left over from a now defunct project.
I will order some 18F27K40 and try out your code as it looks simple and straight forward.
It may be just what I need.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On the 18F27K40 with the 28 pin package it doesn't show a transmit pin for EUART, it shows a receiver pin for UART, so I guess I need to order the 40 pin package, which is a little clumsy for my PC board that I have laid out for general-purpose 28 pin usage
I looking at the allocation table in microchip for this part and it doesn't show EUART TX. For the 28 pin package
Am my correct or am I misreading microchip pin allocation table.
I really need the serial output capability.
Last edit: Paul Haug 2017-10-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The 18F27K40 uses PPS (Peripheral Pin Select) and you can use it to
assign TX to, within reason, any pin of your choice.
Look up PPS in help and also in the Datasheet.
PPS can be confusing at first but a fantastic facility once you grasp its
capabilities.
On the 18F27K40 with the 28 pin package it doesn't show a transmit pin for
EUART, it shows a receiver pin for you start, so I guess I need to order
the 40 pin package, which is a little clumsy for my PC board that I have
laid out or general-purpose 28 pin usage
I looking at the allocation table in microchip for this part and it
doesn't show EUART TX. For the 28 pin package
Am my correct or am I misreading microchip pin allocation table.
I really need the serial output capability.
This chip supports PPS (Peripherial Pin Select) . This basically means you you can assign any Pin on PortB or PortC to be TX (or RX for that matter). TX is simply not assigned by default. This add lots of flexibility.
To assign TX out to a specific Pin, open the PPS tool and enter the specific chip at the top. Then in "Peripheral Output" Select TX1 and assign the pin you want. Let's use RC6 which is the same as most older 28 Pin chips. Then click "Add"
I like to also assign RX even if it is the default so in "Peripheral Input" Slelect RX1 and make it RC7. Then click on "Add". Code will be generated in the output window that you can then copy/paste into your GCB program. It will look something like this:
'Generated by PIC PPS Tool for Great Cow Basic
'PPS Tool version: 0.0.5.11
'PinManager data: v1.55
'
'Template comment at the start of the config file
'
#startup InitPPS, 85
Sub InitPPS
'Module: EUSART1
RX1PPS = 0x0017 'RC7 > RX1
RC6PPS = 0x0009 'TX1 > RC6
TX1PPS = 0x0016 'RC6 > TX1 (bi-directional)
End Sub
'Template comment at the end of the config file
You then need to setup serial in GCB same as before.
The Subroutine "InitPPS" runs at the very beginning of the program, so any peripherial that needs pins assigned should be added here as pins must be assigned before the respective libraries initialize the peripheral devices.
Note that in the code I previously posted that Pins were assigned for the MSSP (I2C) and for CPP1 (PWM)
Pretty cool stuff.
Edit: Corrected my mistake in assigning RX1 to RC5 instead of RC7
Last edit: William Roth 2017-10-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
WOW, thanks all, is there any thing this chip can't do. The PPS is really cool, but I need to study it and learn it's flexability. William that is a great example.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
William,
Yes I will let you know the version niumbers and I ordered from mouser.
Looking at your code I see you are using I2C for debug display so I have a few questions:
;
1) Type or model of LCD unit. I have been using a rs232 type unit, but like to use I2C to learn more about I2C type comm.
2) In your code (see section of code) you show I2C DIR data and clock as inputs but I don't see outputs ??
'Initialise I2C
Dir HI2C_DATA IN ;IN ???? where is out
Dir HI2C_CLOCK IN ;IN ???? " " "
HI2CMode Master
'''Set up LCD
#define LCD_IO 10
#define LCD_I2C_Address_1 0x7E
#define LCD_SPEED Fast
#define LCD_Backlight_On_State 1
#define LCD_Backlight_Off_State 0
CLS
InitLCD 'Just in case but probably unnecessary
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to use HPWM for modulating a proportional hydraulic valve to replace an existing circuit that no longer functions correctly.
I am using a 18F26K20 and I am using a code sample from the basic manual. (code sample was a 16F877A, 20)
I need to get the pulse repetition rate down to 50 Hz.
With the clocks set at 16 MHz I get the proper proportional rate at 1 kHz when I set the HPWM rate to 1
I have tried reducing the clock rate to different values but non work that make any sense below 32 MHz and 16 MHz.
Any suggestions would be of great value.
Here are the rep rates for various #chip 18F26K20 , x
x= 32 rep rate is 2Khz
x=16 rep rate is 1 kHz
x=8 rep rate jumps up to 2 kHz ????
x= 10 rep rate is 100 hz (probably an illegal setting for this chip?
'This will be the pwm modulator for porportional hydrolic valves
'PEH Oct 29 2017
'ASM Ver 0.97.01
'This program will alter the brightness of an LED using
'hardware PWM.
'Select chip model and speed
'Set the CCP1 pin to output mode
DIR PORTC.2 out
Dim Bright as byte ;
'Main code
do
'Turn up brightness over 2.5 seconds
For Bright = 1 to 255
HPWM 1, 1, Bright
wait 10 ms
next
'Turn down brightness over 2.5 seconds
For Bright = 255 to 1
HPWM 1, 1, Bright
wait 10 ms
next
loop
Last edit: Paul Haug 2017-10-30
@Paul. Can share your version of the compiler? I think you are on v09.01. You need to be on v.0.98
Update your setup as i have updated. PMW and I will be using the latest build here to help you.
Based on using v0.98.0x (I have v0.98.01 here... I will release this week).
Upgrade your installation please.
Is your question... what are the PWM frequencies (a range) supported at each chip frequency?
Last edit: Anobium 2017-10-30
And, if you want to check that a PWM frequency is supported by a chip frequency when using CCP/PWM.
Try the fixed mode first. This will issue an error message if the PWM frequency is NOT supported by a chip frequency.
Also, in the latest build you can test...
:-)
Last edit: Anobium 2017-10-30
I have upgraded to V0.98.00 as you suggested, but any thing below clock selection (internal) of 16 or 32 mhz gives strange results on the HPWM repition rate.
Your question of:
Is your question... what are the PWM frequencies (a range) supported at each chip frequency?
That is my problem, I need 50Hz (or approximatly) for the hydro valves to operate correctly.
.
I will try your suggestions today with the HserPrint as a debug test.
Thanks
Last edit: Paul Haug 2017-10-30
Typically you would need 14-16bit PWM or CCP for 50Hz refresh rates, at least with a reasonable clock source.
Here William uses a TMR1 (16bit) interrupt and "Wait cycles" to update 4 servos https://sourceforge.net/p/gcbasic/discussion/629990/thread/8e7f88d7/#0ce3
Here is tutorial on using an AVR for 50Hz PWM updates (non blocking) https://sourceforge.net/p/gcbasic/discussion/projects%26guides/thread/66153766/#ae47
Thanks kent_twt4,
That certianly gives me another approach since my application is closely related to RC servo control, except I need full (0-100%) pulse width control, but with some tweeking that code should work.
And... look in your installation.
..Demos\Interrupt_and_Timer_Solutions\Interrupt - Timed examples
There is a set of calculators - this WILL show the range of frequencies per a selected chip freq. See the TimerCalculator for the calculator for 50 hz... it is a max chip freq of 8mhz on your chip.
:-)
The 18f26k20 has a TMR3 to play with too, so you could sync up a full scale PWM duty cycle using a TMR3 count (or overflow) + interrupt, in the TMR1 interrupt.
As Evan shows, plenty of ways to get what you need. Using the CCP special event trigger is another option.
@Paul
Aparantly neither Microchip nor GCB figured that anyone would want/need to use Hardware PWM at less than 1Khz.
The 18F26K20 only allows for one possible clock source for TMR2 and that is FOSC/4. So we are stuck with that. Using the internal osc (chip MHz) we can get to 50 hz PWM only one way. That is by setting the Chip MHz to 2 and then manually setting the Timer2 Prescale to 128 and the Timer2 Period Register ( PR2) to 152
The problem with this is that changing the duty cycle on-the-fly using HPWM function will likely be glitchy as it will reset the timer period to an unwanted value. You may be able to write the CCPR1H duty register directly, bypassing the high level GCB HPWM command which always reset the timer period.
My suggestion for 50Hz PWM with GCB on your chip is to bit bang it usiing a 16 bit timer. Optionally you could get a more modern chip that supports multple clock sources to TIMER2//4/6 and that has Dedicated PWM modues.
50 Hz is a common frequency for Servo contol. If you are wanting to control a servo then please indicate so as 8- bit PWM will not give the resolution necessary for good Servo control.
Below is Example Code (Untested) that should show to get 50 hz PWM using a 18F26K20 with 2Mhz Internal Clock Source . I created a sub to set duty cycle as a percentage to eliminate to need to use HPWM to change duty cycle. Use this only if you can live with a 2 Mhz system cock.
50Hz pwm would have to lower chip clock speed to get pwm resolution I found.
for a servo why not interrupt pulseout..my idea of servo is model controller actuator not servo motor.
~~~
;set up servo interrupt 50Hz
on interrupt timer1overflow Call servo
inittimer1(OSC,PS1_2)
Starttimer 1
;
sub servo ;servo interrupt
settimer 1, 25535
pulseout Servo_Pin , servoposition 10us
end sub
~~~
Many thanks, I will work on the various suggestions.
This is for a rather large hydraulic control system that uses proportional valves that look like solenoids. By scoping the working units I see the pulses are at 50Hz and duty cyle of the pulses is 0 to 100%, zero being closed and 100% being fully opened.
* 8 bit resolution will be fine, the operator uses a joy stick to control the speed of lift, drive, swing of a platform. Many safety switches and limits are used that the uProc will not control.
The software will be doing other things also, like logging temp, operating relays and indicator lights and a serial output.
EDIT: Added some comment info.
Last edit: Paul Haug 2017-10-30
@Paul
The 18F26K20 has 64K Flash and 4K SRAM. So I assume this chip was not just randomly selected, but was slelected for its large amount of memory an/or its 64MHz max speed
A newer alternative is the 18F26K40. This chip has the same memory & speed specifications but includes a wealth of new features and new perieherals.
In regards to your applcation the 18F26K40 has updated Timer2/4/6 modules that support multiple clock sources, and it also has a Reference Clock Module. This makes it relatively easy to get a 50 Hz PWM while operating the chip at up to 64Mhz.
The idea is to clock Timer 2 using the Reference Clock, then to use Timer2 as the clock source for the CCP or PWM module used for the PWM.
While GCB's PWM library does not yet support all the possible clock source combinations for HPWM, with a few extra lines of code a 50Hz is quite possible.
And the newer/better chips are less expensive.
Cost Comparison (Mouser):
18F26K20 ... $3.02
18F26K40 ... $2.04
18F27K40 ... $2.34
Below is working example code using a PIC18F27K40 that I had laying around, the only difference being is that the 18F27K40 has 128K Flash instead of 64K with the 18F26K40. Hook your scope up to PIN C.1 to see the output. Or attach an LED.
Many thanks William. I used the 18F26K20 because I had a tube full left over from a now defunct project.
I will order some 18F27K40 and try out your code as it looks simple and straight forward.
It may be just what I need.
On the 18F27K40 with the 28 pin package it doesn't show a transmit pin for EUART, it shows a receiver pin for UART, so I guess I need to order the 40 pin package, which is a little clumsy for my PC board that I have laid out for general-purpose 28 pin usage
I looking at the allocation table in microchip for this part and it doesn't show EUART TX. For the 28 pin package
Am my correct or am I misreading microchip pin allocation table.
I really need the serial output capability.
Last edit: Paul Haug 2017-10-31
The 18F27K40 uses PPS (Peripheral Pin Select) and you can use it to
assign TX to, within reason, any pin of your choice.
Look up PPS in help and also in the Datasheet.
PPS can be confusing at first but a fantastic facility once you grasp its
capabilities.
On 31 October 2017 at 22:30, Paul Haug binary1248@users.sf.net wrote:
Sorry, but you are incorrect.
This chip supports PPS (Peripherial Pin Select) . This basically means you you can assign any Pin on PortB or PortC to be TX (or RX for that matter). TX is simply not assigned by default. This add lots of flexibility.
To assign TX out to a specific Pin, open the PPS tool and enter the specific chip at the top. Then in "Peripheral Output" Select TX1 and assign the pin you want. Let's use RC6 which is the same as most older 28 Pin chips. Then click "Add"
I like to also assign RX even if it is the default so in "Peripheral Input" Slelect RX1 and make it RC7. Then click on "Add". Code will be generated in the output window that you can then copy/paste into your GCB program. It will look something like this:
You then need to setup serial in GCB same as before.
The Subroutine "InitPPS" runs at the very beginning of the program, so any peripherial that needs pins assigned should be added here as pins must be assigned before the respective libraries initialize the peripheral devices.
Note that in the code I previously posted that Pins were assigned for the MSSP (I2C) and for CPP1 (PWM)
Pretty cool stuff.
Edit: Corrected my mistake in assigning RX1 to RC5 instead of RC7
Last edit: William Roth 2017-10-31
WOW, thanks all, is there any thing this chip can't do. The PPS is really cool, but I need to study it and learn it's flexability. William that is a great example.
I have ordered 18F27K40 chips to use and explore some of it's many options.
Thanks William.
Great Paul,
Please do me a favor. When they arrive can you tell me what silicon revision you receive and where you ordered them from. I have revison a002.
I googled 18F27K40 and nothing..?
That is wierd when I google it this is the first result:
http://www.microchip.com/wwwproducts/en/PIC18F27K40
When using google to search for a PIC chip, I find that the search results are better when "PIC" is included with the model number. e.g. "PIC18F27K40"
True. Looks capable from glimpse. guess it needs pk3 to program features if it's got programable pins.
Thanks.
William,
Yes I will let you know the version niumbers and I ordered from mouser.
Looking at your code I see you are using I2C for debug display so I have a few questions:
;
1) Type or model of LCD unit. I have been using a rs232 type unit, but like to use I2C to learn more about I2C type comm.
2) In your code (see section of code) you show I2C DIR data and clock as inputs but I don't see outputs ??
' Define I2C settings
#define HI2C_BAUD_RATE 125
#define HI2C_DATA PORTC.4
#define HI2C_CLOCK PORTC.3 ;unnecessary