I am not able to figure out how to redirect on the RC3 pin of the PIC18LF24J11 the output of CCP1 PWM... I think the following short program should give me a PWM on pin 14 (RC3), but do not get anything out of
it:
The PPS will be the start of the fun, the GCBASIC PWM will not work as all the CCP/PWM registers are different.
See below for potential PPS fix, but this is a very different chip to other 18Fs. This was the start of the PPS chips and Microchip totally changed the approach on later chips. MPLAB PPS does not support this chip...
My advice. Place chip in bin and get a modern chip.
You have to figure it our from the datasheet/internet and write the registers. MPLAB MCC does not support this chip, so, I cannot lift the code from there.
And, always use #option Explicit it would have shown the registers were not defined.
Evan
#chip18lf24j11,8#optionExplicit#startupInitPPS,85#definePPSToolPart18LF24J11SubInitPPS// Assign remapable RP14 to CCP/PWMRPOR14=0x000EEndSubDIRportc.3out/* Add initialisation of PWM here. This specific registers uses for CCP1/PWM Timer 1 or 3 ( typical chip uses Timer2, with later chips using Timer4 and Timer6) GCBASIC PWM initialisation only uses 2, 4 or 6. CCP1CON - CCP Control Register - has different bits PR2 - Timer Period - not applicable T2CON - Timer2 control - not applicable, used T1/3Con T2CLKCON- Clock Source Selection - not applicable, but, TCLKCON exists CCPR1H - Duty cycle H CCPR1L - Duty cycle L CCPTMRS0- Timer Selection - not present */DoLoop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, understood..
I won't loose too much time on it to make it work. It's a pity, tough, as all the other stuff was working well - I was trying to make a 7seg clock out of it, as it's the only chip I currently have on my desk with an RTC onboard. Will look after a 28 pin similar device, but more modern.
Thanks, bye.
GC
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry to bother again on this, but I can't get the RTC working..
I think I did all the necessary settings to enable the module and it's clock correctly.
I see on the scope that the T1 oscillator is resonating with the external xtal at the 32Khz, but when reading minutes and second values, I get out fixed values, non BCD coded, and it seems that the RTC is not counting at all.. Any suggestion?
Rgds,
GC
'sets the RTC clock to Timer1 oscillator as external crystal 32768Hz, to feed the internal RTC
T1OSCEN=1 'enable T1 external oscillator
'enables the RTC peripheral
-#CONFIG RTCOSC = T1OSCREF
RTCWREN = 1 'enable writing to the RTC registers
RTCEN = 1 'enables RTC
I think I finally figured out the way to unlock it..
My instructions sequence were correct, but there is a "misterious", or at least not well documented description of a Control Lock register, wich requires the following sequence of writes to the "virtual" (not a physical register) EECON2 register:
EECON2=0x55;
EECON2=0xAA;
This is needed to enable Table read/writes of banks of memory fm Flash(16bits) to Ram (8bits). It also enable the writing of PPS register that contain the RTC portion..
So, if the user does not make such write sequence to EECON2, he is not actually setting internal connections between the modules option..
The explaination is in below here for yr convenience.. However, It's almost impossible to figure it out reading the RTC and TMR1 sections.. A very poorly documented job done by Microchip on this module.
Anyway, now it finally works, this is the sequence to initialize the RTC in GCBasic, if others need it too:
'sets the RTC clock to Timer1 oscillator as external crystal 32768Hz, to feed the internal RTC
T1OSCEN=1 'enable T1 external oscillator
'enables the RTC peripheral
-#CONFIG RTCOSC = T1OSCREF
EECON2=0x55;
EECON2=0xAA;
RTCWREN = 1 'enable writing to the RTC registers
RTCEN = 1 'enables RTC
Thanks and regards,
GC
From the Datasheet:
Section 9.7.4.1 "Control Register Lock"
Under normal operation, writes to the RPINRx and
RPORx registers are not allowed. Attempted writes will
appear to execute normally, but the contents of the
registers will remain unchanged. To change these registers,
they must be unlocked in hardware. The register
lock is controlled by the IOLOCK bit (PPSCON<0>).
Setting IOLOCK prevents writes to the control
registers; clearing IOLOCK allows writes.
To set or clear IOLOCK, a specific command sequence
must be executed:
1. Write 55h to EECON2<7:0>.
2. Write AAh to EECON2<7:0>.
3. Clear (or set) IOLOCK as a single operation.
IOLOCK remains in one state until changed. This
allows all of the PPS registers to be configured with a
single unlock sequence followed by an update to all
control registers, then locked with a second lock
sequence.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am not able to figure out how to redirect on the RC3 pin of the PIC18LF24J11 the output of CCP1 PWM... I think the following short program should give me a PWM on pin 14 (RC3), but do not get anything out of
it:
chip 18LF24J11,8
startup InitPPS, 85
'Set the PPS of the PWM output to pin 14, RC3
Sub InitPPS
End Sub
HPWM 1, 4, 50
Even using this version I get the same result..
UNLOCKPPS
CCP1PPS = 0x0014 'CCP1 output on pin 14, RC3
LOCKPPS
Any suggestions?
Thanks,
GC
I also tried this, looking after other examples of similar uCs generated by the PPSTool..
But also this is not working.
#chip 18lf24j11,8
#startup InitPPS, 85
_#define PPSToolPart 18LF24J11
Sub InitPPS
dir portc.3 out
HPWM 1, 4, 50
The PPS will be the start of the fun, the GCBASIC PWM will not work as all the CCP/PWM registers are different.
See below for potential PPS fix, but this is a very different chip to other 18Fs. This was the start of the PPS chips and Microchip totally changed the approach on later chips. MPLAB PPS does not support this chip...
My advice. Place chip in bin and get a modern chip.
You have to figure it our from the datasheet/internet and write the registers. MPLAB MCC does not support this chip, so, I cannot lift the code from there.
And, always use
#option Explicit
it would have shown the registers were not defined.Evan
Ok, understood..
I won't loose too much time on it to make it work. It's a pity, tough, as all the other stuff was working well - I was trying to make a 7seg clock out of it, as it's the only chip I currently have on my desk with an RTC onboard. Will look after a 28 pin similar device, but more modern.
Thanks, bye.
GC
See "..demos\Real_Time_Clock_Solutions\RTCC_Microchip_16F19156_ANSI_SERIAL_TERMINAL_VBATEN.gcb"
A new chip.. there a few demos for the new RTCC chip.
Well, I tought to give it the last try to it with your suggestion:
RPOR14 = 0x000E
And it works! Now that the pin it's correctly remapped, the HPWM command works fine..
Thank you Evan, have a good day.
GC
Can't get the RTC clock source set to Timer1 oscillator, where I put a 32Khz xtal on pin 11/12..
None of these commands work:
'RTCOSC =1
'CONFIG3L.RTCOSC=1
'CONFIG3L.1=1
I always get "Variable CONFIG3L (or RTCOSC) was not explicitly declared"..
There is something to change in the chip .DAT file, perhaps?
Use PICINFO to set them. Setting like that will not work.
Take the output from PICINFO and paste into your program.
To access PICINFO via GCODE/<Function Key F4/Type PICINFO
Sorry to bother again on this, but I can't get the RTC working..
I think I did all the necessary settings to enable the module and it's clock correctly.
I see on the scope that the T1 oscillator is resonating with the external xtal at the 32Khz, but when reading minutes and second values, I get out fixed values, non BCD coded, and it seems that the RTC is not counting at all.. Any suggestion?
Rgds,
GC
'sets the RTC clock to Timer1 oscillator as external crystal 32768Hz, to feed the internal RTC
T1OSCEN=1 'enable T1 external oscillator
'enables the RTC peripheral
-#CONFIG RTCOSC = T1OSCREF
RTCWREN = 1 'enable writing to the RTC registers
RTCEN = 1 'enables RTC
sub read_min_sec
end sub
The 16F19156 ( see https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/Real_Time_Clock_Solutions/RTCC_Microchip_16F19156_I2C_LCD_VBATEN.gcb ) is totally different.
but, found this... does this start set it running?
EECON2 = 0xAA
RTCCFG.RTCEN = 0 //Disable RTC
RTCCFG.RTCWREN = 1 //Enable writing to RTC timer
RTCCFG.RTCPTR0 = 1 //Set pointers before setting date
RTCCFG.RTCPTR1 = 1
RTCVALL = 0x14 //Minutes
RTCVALL = 0x1F //Hours
RTCVALL = 0x09 //Day
RTCVALL = 0x00 //Year
RTCCFG.RTCPTR0 = 1 //Set pointers before setting date
RTCCFG.RTCPTR1 = 1
RTCVALH = 0x00 //RESERVED Always 00
RTCVALH = 0x08 //Month
RTCVALH = 0x00 //Weekday
RTCVALH = 0x0D //Minutes
PIE3.RTCCIE = 1 //RTCC Interrupt enabled
PIR3.RTCCIF = 0
RTCCFG.RTCEN = 1 //Enable RTC
RTCCFGRTCWREN = 0 //Disable writing to RTC timer
RTCCAL = 0x00
I think I finally figured out the way to unlock it..
My instructions sequence were correct, but there is a "misterious", or at least not well documented description of a Control Lock register, wich requires the following sequence of writes to the "virtual" (not a physical register) EECON2 register:
EECON2=0x55;
EECON2=0xAA;
This is needed to enable Table read/writes of banks of memory fm Flash(16bits) to Ram (8bits). It also enable the writing of PPS register that contain the RTC portion..
So, if the user does not make such write sequence to EECON2, he is not actually setting internal connections between the modules option..
The explaination is in below here for yr convenience.. However, It's almost impossible to figure it out reading the RTC and TMR1 sections.. A very poorly documented job done by Microchip on this module.
Anyway, now it finally works, this is the sequence to initialize the RTC in GCBasic, if others need it too:
'sets the RTC clock to Timer1 oscillator as external crystal 32768Hz, to feed the internal RTC
T1OSCEN=1 'enable T1 external oscillator
'enables the RTC peripheral
-#CONFIG RTCOSC = T1OSCREF
EECON2=0x55;
EECON2=0xAA;
RTCWREN = 1 'enable writing to the RTC registers
RTCEN = 1 'enables RTC
Thanks and regards,
GC
From the Datasheet:
Section 9.7.4.1 "Control Register Lock"
Under normal operation, writes to the RPINRx and
RPORx registers are not allowed. Attempted writes will
appear to execute normally, but the contents of the
registers will remain unchanged. To change these registers,
they must be unlocked in hardware. The register
lock is controlled by the IOLOCK bit (PPSCON<0>).
Setting IOLOCK prevents writes to the control
registers; clearing IOLOCK allows writes.
To set or clear IOLOCK, a specific command sequence
must be executed:
1. Write 55h to EECON2<7:0>.
2. Write AAh to EECON2<7:0>.
3. Clear (or set) IOLOCK as a single operation.
IOLOCK remains in one state until changed. This
allows all of the PPS registers to be configured with a
single unlock sequence followed by an update to all
control registers, then locked with a second lock
sequence.