I'm trying to get a PWM signal out of a 16F1705. It has a two 10 bit PWMs which are called PWM3 and PWM4.
First the PPS tool does not cover the PWM module, but I have configured it the hard way.
Second the help files suggest that the 10 bit channels should be 5,6 or 7. Should I put in 3 for PWM3?
Should the duty be a 10 bit number?
Here is the code (it does not work)
And I was misguided to suspect the PPStool which works fine.
So what is the PWM2 and PWM3 for?
I'm now going to try to get the complementary output generator (COG) to convert this into a h-bridge type output. GCBasic does not seem to have covered the COG module as yet.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
re usage. You are using the PWM CCP method. So, 10 bit is not available. But, you select any of the available. CCP modules, noting, that the PWM CCP module always uses timer 2.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
On the 16F1705 there is a PWM2OUT and PWM3OUT that can be directed using the PPS to any pin.
Which was what I was trying initially were PWM3out was directed to RC5 ( and it did not work).
Can you provide any help on getting the PWM module as the PWM source?
Although I've got the ouput on the oscilloscope and the period and duty cycle look good enough for my purposes. Still using the dedicated module would be good for future reference.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
'Generated by PIC PPS Tool for Great Cow Basic'PPS Tool version: 0.0.5.5'PinManager data: 07/03/2017''Template comment at the start of the config file' #startup InitPPS, 85 Sub InitPPS'Module: PWM3RC5PPS=0x000E'PWM3OUT > RC5 End Sub'Template comment at the end of the config file
with
HPWM 3, 40, 50, 2
Now... when I say it should work.... you need the very latest. PWM.H. I will attach when. I. get to home.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First file I get a cycle of about 3 us (1.2us on 2.1 us off).
Second file does not compile
compiled.asm:245:Error[113] Symbol not previously defined: "ADCS1"
compiled.asm:246:Error[113] Symbol not previously defined: "ADCS0"
Error[181] Error generating hex file.
Third file the output is high (no cycling)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The final test programs. These all work for me. I am using 0.97.02 with the very latest pwm.h (which I have just reposted to the link I sent you).
001 - user
002 - use the PWM software method
003 - uses CCP1/PWM method
004 - uses PMW3 on timer 2
005 - uses PMW4 on timer 2
006 - uses both PMW3 and PMW4 on timer 2 and 6 respectively.
007 - uses both PMW3 and PMW4 on timer 2 and 6 respectively but using optimisation - save about 340 bytes
V96.00. It was the GPASM that was out of date. I'll use the GCASM.
Now the second file compiles and gives a semi-random pulse length (as you would expect with AN0 floating).
The third file now gives Vss and no pulsing.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can you please try to use GCASM for the time whilst we are testing? same basline.
001 - works
002 - semi random? change the ReadAD(AN0) to 127 - do you get 50% duty?
003 - Sorry, works here with GCASM and MPASM v5.68. You need to sort this out before moving on to 004.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Basically the ones using CCP work and the ones using PWM don't (changing the timer2 to timer6 does not change things)
~~~~~~~~~
chip 16LF1705,8
config OSC=INTOSC, MCLRE=Off, WDT=off, boren=off
unlockpps
RC5PPS = 0x0E 'PWM3 > RC5
'RC5PPS = 0x0C 'ccp1 > RC5
lockpps
dir portc.5 out
'Main code
do
'Turn up brightness over 2.5 seconds
For Bright = 1 to 255
HPWM 3, 40, Bright, 2
'HPWM 1,40, bright
wait 10 ms
next
'Turn down brightness over 2.5 seconds
For Bright = 255 to 1
HPWM 3, 40, Bright, 2
'HPWM 1,40,bright
wait 10 ms
next
loop
~~~~~~~~
So the program above does not work, but if the REMed lines are swapped it does.
I deleted my pwm.h file and replaced it with the one in the link you sent.
I had to pull down the osc frequency as I am using low voltage.
Last edit: David Stephenson 2017-05-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Recommend a reinstall and use the stock installation. The stock installation now support GPASM. :-)
See attached - source and the HEX files with the PWM library. This library must be used and you MUST be using the latest version of the installation - why? cus, we updated all the chip files and this could be related (but, I have no idea what the issue from the test results).
I just retested and all tests pass.
001 - Use port toggle method. This shows the port is working.
002 - Use the PWM software method. This shows the software PWM is working and the scope (or, whatever is attached) can measure the results.
003 - Use the CCP1/PWM method. This shows the CCP1 module is operational AND timer 2 is setup correctly... if CCP1 or the timer was not setup correctly there is no PWM
004 - Use the PMW3 on timer 2. This shows the PMW3 module is operational AND timer 2 is setup correctly... if PMW3 or the timer was not setup correctly there is no PWM. This uses a totally different method to #003 - so, this is an important and valid test.
005 - Use the PMW4 on timer 2. This shows the PMW4 module is operational .. if PMW4 was not setup correctly there is no PWM. This uses a totally different method to #005/PWM3 - so, this is an important and valid test.
006 - Use PMW4 on timer 2 and timer 6. This shows the PMW4 module is operational AND timer 2 and timer 4 are setup correctly... if PMW4 or the timer was not setup correctly there is no PWM.
007 - Use both PMW3 and PMW4 on timer 2 and 6 respectively but using GCB code optimisation - saves about 340 bytes. This shows the PMW3 and PMW4 module are operational AND timer 2 and timer 6 are setup correctly AND PPS swapping of the output is working AND the code optimisation is yielding the correct resulots. If anything is not setup correctly there is no PWM. This is an important and valid final test.
See attached.
Test with the HEXs. If they do not work then look at your microcontroller configuration. If they do work.... resinstall and use the stock installation.
I am really surprised - we need to up the communications. My feedback.
You should be able to use the standard batch files.
You should consisder using GCASM not MPASM as this make the whole experience easier. If you have a bug we may ask you to use MPASM but you should be ok to use GCASM.
MPLAB-IPE. This one surprised me. Please use the PK2 GUI within your Great Cow BASIC installation as this supports the chip you are using, or, install the PK3 GUI within your Great Cow BASIC installation as this supports the chip you are using by update the chip data files.
My initial review - but, I do not have the time to figure out if the batch file is the source of the issue.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For those following along. Here is a set of 16f887a PWM tests - these are all intended to work correctly.
Hook up a scope to portc.2 which is the CCP1 port - CCP1 is CCP1/PWM port.
001 - Use port toggle method. This shows the port is working.
002 - Use the PWM software method. This shows the software PWM is working and the scope (or, whatever is attached) can measure the results.
003 - Use the CCP1/PWM method. This shows the CCP1 module is operational AND timer 2 is setup correctly... if CCP1/PWM or the timer was not setup correctly there is no PWM
004 - Uses CCP1/PWM method but using GCB code optimisation - saves about 53 bytes. This shows the CCP1/PWM module is operational AND timer 2 are setup correctly AND the code optimisation is yielding the correct resulots. If anything is not setup correctly there is no CCP1/PWM. This is an important and valid final test.
Updated the ZIP as one of the source file had the incorrect title - renamed and resaved.
I'm now going to see if I can work out the mysteries of the "complementary output generator module" as I want to have two pins giving a PWM signal but out of phase with each other.
I was originally going wrong with the PWM by setting the duty cycle longer than the period so the pin stayed permanently on.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to get a PWM signal out of a 16F1705. It has a two 10 bit PWMs which are called PWM3 and PWM4.
First the PPS tool does not cover the PWM module, but I have configured it the hard way.
Second the help files suggest that the 10 bit channels should be 5,6 or 7. Should I put in 3 for PWM3?
Should the duty be a 10 bit number?
Here is the code (it does not work)
Sorted it out. How confusing rather than connecting to the PWM it needs to be connected to the CCP.
And I was misguided to suspect the PPStool which works fine.
So what is the PWM2 and PWM3 for?
I'm now going to try to get the complementary output generator (COG) to convert this into a h-bridge type output. GCBasic does not seem to have covered the COG module as yet.
Glad you got it sorted.
We support three methods for PWM. A simple fixed PMW, PWM CCP and PWM using the microntroller PWM module.
Have. a. look at the Help. I would accept any help to improve and clarfy the PWM section.
Where did you see PWM2 and PWM3? I some context.
re usage. You are using the PWM CCP method. So, 10 bit is not available. But, you select any of the available. CCP modules, noting, that the PWM CCP module always uses timer 2.
On the 16F1705 there is a PWM2OUT and PWM3OUT that can be directed using the PPS to any pin.
Which was what I was trying initially were PWM3out was directed to RC5 ( and it did not work).
Can you provide any help on getting the PWM module as the PWM source?
Although I've got the ouput on the oscilloscope and the period and duty cycle look good enough for my purposes. Still using the dedicated module would be good for future reference.
This should work.
with
Now... when I say it should work.... you need the very latest. PWM.H. I will attach when. I. get to home.
@David. I have sent a PM with a download link. Please test and let me know the results.
This new file is part of the next release. You get it early!
Also, the Online Help will be updated tonight to reflect the support for PWM3 and PWM4.
No doesn't work (with the new pwm.h file). Pin RC.5 is at ground.
I've also tried doing it by setting the registers directly, and again it does not work, but the pin is now at Vdd.
Work through the issue for me, please.
Try the attachments.
Each test will proove or disproove what is happening. I have lifted the examples from the Help.
What are your results?
First file I get a cycle of about 3 us (1.2us on 2.1 us off).
Second file does not compile
compiled.asm:245:Error[113] Symbol not previously defined: "ADCS1"
compiled.asm:246:Error[113] Symbol not previously defined: "ADCS0"
Error[181] Error generating hex file.
Third file the output is high (no cycling)
What version of Great Cow BASIC please?
These clearly compile here and something is not quite right.
The final test programs. These all work for me. I am using 0.97.02 with the very latest pwm.h (which I have just reposted to the link I sent you).
001 - user
002 - use the PWM software method
003 - uses CCP1/PWM method
004 - uses PMW3 on timer 2
005 - uses PMW4 on timer 2
006 - uses both PMW3 and PMW4 on timer 2 and 6 respectively.
007 - uses both PMW3 and PMW4 on timer 2 and 6 respectively but using optimisation - save about 340 bytes
Last edit: Anobium 2017-05-24
V96.00. It was the GPASM that was out of date. I'll use the GCASM.
Now the second file compiles and gives a semi-random pulse length (as you would expect with AN0 floating).
The third file now gives Vss and no pulsing.
Can you please try to use GCASM for the time whilst we are testing? same basline.
001 - works
002 - semi random? change the ReadAD(AN0) to 127 - do you get 50% duty?
003 - Sorry, works here with GCASM and MPASM v5.68. You need to sort this out before moving on to 004.
And..... can you get on Google Chat? We are having a conversation via the posting. Send me your Google Chat address via a PM
Basically the ones using CCP work and the ones using PWM don't (changing the timer2 to timer6 does not change things)
~~~~~~~~~
chip 16LF1705,8
config OSC=INTOSC, MCLRE=Off, WDT=off, boren=off
unlockpps
RC5PPS = 0x0E 'PWM3 > RC5
'RC5PPS = 0x0C 'ccp1 > RC5
lockpps
dir portc.5 out
'Main code
do
'Turn up brightness over 2.5 seconds
For Bright = 1 to 255
HPWM 3, 40, Bright, 2
'HPWM 1,40, bright
wait 10 ms
next
'Turn down brightness over 2.5 seconds
For Bright = 255 to 1
HPWM 3, 40, Bright, 2
'HPWM 1,40,bright
wait 10 ms
next
loop
~~~~~~~~
So the program above does not work, but if the REMed lines are swapped it does.
I deleted my pwm.h file and replaced it with the one in the link you sent.
I had to pull down the osc frequency as I am using low voltage.
Last edit: David Stephenson 2017-05-24
This is what I am using to compile the program - maybe there is a problem here.
Recommend a reinstall and use the stock installation. The stock installation now support GPASM. :-)
See attached - source and the HEX files with the PWM library. This library must be used and you MUST be using the latest version of the installation - why? cus, we updated all the chip files and this could be related (but, I have no idea what the issue from the test results).
I just retested and all tests pass.
001 - Use port toggle method. This shows the port is working.
002 - Use the PWM software method. This shows the software PWM is working and the scope (or, whatever is attached) can measure the results.
003 - Use the CCP1/PWM method. This shows the CCP1 module is operational AND timer 2 is setup correctly... if CCP1 or the timer was not setup correctly there is no PWM
004 - Use the PMW3 on timer 2. This shows the PMW3 module is operational AND timer 2 is setup correctly... if PMW3 or the timer was not setup correctly there is no PWM. This uses a totally different method to #003 - so, this is an important and valid test.
005 - Use the PMW4 on timer 2. This shows the PMW4 module is operational .. if PMW4 was not setup correctly there is no PWM. This uses a totally different method to #005/PWM3 - so, this is an important and valid test.
006 - Use PMW4 on timer 2 and timer 6. This shows the PMW4 module is operational AND timer 2 and timer 4 are setup correctly... if PMW4 or the timer was not setup correctly there is no PWM.
007 - Use both PMW3 and PMW4 on timer 2 and 6 respectively but using GCB code optimisation - saves about 340 bytes. This shows the PMW3 and PMW4 module are operational AND timer 2 and timer 6 are setup correctly AND PPS swapping of the output is working AND the code optimisation is yielding the correct resulots. If anything is not setup correctly there is no PWM. This is an important and valid final test.
See attached.
Test with the HEXs. If they do not work then look at your microcontroller configuration. If they do work.... resinstall and use the stock installation.
I just looked at the batch file.
I am really surprised - we need to up the communications. My feedback.
You should be able to use the standard batch files.
You should consisder using GCASM not MPASM as this make the whole experience easier. If you have a bug we may ask you to use MPASM but you should be ok to use GCASM.
MPLAB-IPE. This one surprised me. Please use the PK2 GUI within your Great Cow BASIC installation as this supports the chip you are using, or, install the PK3 GUI within your Great Cow BASIC installation as this supports the chip you are using by update the chip data files.
My initial review - but, I do not have the time to figure out if the batch file is the source of the issue.
For those following along. Here is a set of 16f887a PWM tests - these are all intended to work correctly.
Hook up a scope to portc.2 which is the CCP1 port - CCP1 is CCP1/PWM port.
001 - Use port toggle method. This shows the port is working.
002 - Use the PWM software method. This shows the software PWM is working and the scope (or, whatever is attached) can measure the results.
003 - Use the CCP1/PWM method. This shows the CCP1 module is operational AND timer 2 is setup correctly... if CCP1/PWM or the timer was not setup correctly there is no PWM
004 - Uses CCP1/PWM method but using GCB code optimisation - saves about 53 bytes. This shows the CCP1/PWM module is operational AND timer 2 are setup correctly AND the code optimisation is yielding the correct resulots. If anything is not setup correctly there is no CCP1/PWM. This is an important and valid final test.
Updated the ZIP as one of the source file had the incorrect title - renamed and resaved.
Last edit: Anobium 2017-05-25
I've got it to work.
~~~~~~
chip 16F1705,8
config OSC=INTOSC, MCLRE=Off, WDT=off, boren=off
unlockpps
RC5PPS = 0x0F 'PWM4 > RC5
lockpps
dir portc.5 in 'disable pwm pin
ccptmrs=b'00000000' 'select timer2 for all
pwm4con=b'00000000' 'clr reg
pr2=49 'set period 40 kHz
pwm4dch=25 '100 ->50%
pwm4dcl=0 'set duty cycle
pir1.1=0 'clr interrupt timer2
t2con=b'00000100' 'start timer
dir portc.5 out 'enable PWM pin
set pwm4con.7 on 'enable PWM4
do
wait 5 sec
set pwm4con.7 off
wait 5 sec
set pwm4con.7 on
loop
~~~~~~~
Well done.
I guess I should not have spent my time trying to resolve - we will never know where the issue is.
I'm now going to see if I can work out the mysteries of the "complementary output generator module" as I want to have two pins giving a PWM signal but out of phase with each other.
I was originally going wrong with the PWM by setting the duty cycle longer than the period so the pin stayed permanently on.
See here https://sourceforge.net/p/gcbasic/blog/2017/05/pwm-using-the-great-cow-basic-toolbox-to-setup-your-pwm-channel/ for a blog of how you can use the inbuilt Great Cow BASIC to calculate timer and duty values for static (or non changing) frequency and duty.