Nice video, what is gcb pwm ?
Say I use a mega328 then pins with hpwm are portd and for legacy it's just
DIR PORTD.5 out
#define PWM_Freq 38 'Frequency of PWM in KHz
#define PWM_Duty 50 'Duty cycle of PWM (%)
PWMOn
On a pic I guess it's pins with hardware pwm...like a 18f25k22 has 4 pwm pins.
On mega328 does that mean any portd pin set as out will have 38khz on it?
Moving on to next pwm in video..see image-the code shows dir portb out, not which port bit. typo?
pwmon/off is easier than setting ocr0,tccr0,wgm01 or other stuff to get pwm.
In the case of 18f25k22, looking at the data sheet doesn't say "these pins have hardware pwm", just timers and ccp modules.
In the image from the video, it says dir portb out. Why not portb bit no, as pics don't have whole ports that can be pwm like mega328?
With 328 ,is any port with pwm set as output going to have the same pwm signal on it?
It's not obvious. If the command was portx.xpwmon/off it would be.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
pwmon/off is easier than setting ocr0,tccr0,wgm01 or other stuff to get pwm.
Yes, if someone has time to improve then I am sure we can make AVR the same.
In the case of 18f25k22, looking at the data sheet doesn't say "these pins have hardware pwm", just timers and ccp modules.
The 18f25k22 has two CCP/PWM channels. Numbered 4 and 5 with selected timers as 2, 4 or 6.
In the image from the video, it says dir portb out. Why not portb bit no, as pics don't have whole ports that can be pwm like mega328?
Dir port was pure lazyness by me as have been testing extensively and I was changing PWM and CCP/PWM a lot. Typically, one PWM channel per port. However, with PPS you could make a port PWM.
With 328 ,is any port with pwm set as output going to have the same pwm signal on it?
I think not. One PWM per Port on the AVRs
It's not obvious. If the command was portx.xpwmon/off it would be.
Pretty obvious. The parameter is the channel. Like 4=CCP4, 5=CCP5 etc etc. Noting that you could have a number being a CCP/PWM or a PMW module. It is all down to the device you are using. So, to get the correct parameter.... examine the datasheet... or do I as do... examine the 18f25k22.dat file and search for CCPXCON and/or PWMXCON as these will help you understand the capabilities
And, this wont be so obvious. Support ECCP. the datasheet masks this... see the datasheet for (E)CCP. The ECCP/PWM on the 18f25k22 (ECCP/PWM has been deprecated by Microchip) is something I have not personally tested but you can easily get working by setting the correct register(s)/bit(s) - but, it should work. ECCP/PWM is on channel 1, 2 or 3 on the 18f25k22.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With the AVR devices it is better to think of HPWM in terms of Timer/Counter numbers like TC0, TC1, and TC2 for the mega328. Each TCx represents a frequency independent PWM module. With GCB TC0 and TC2 can only have one PWM, while TC1 can have two PWM for the mega328 device. Large pinout devices like the mega2560 can have three PWM on TC1, TC3, TC4, and TC5.
When thinking of Ports, the mega328 can have two frequency independent PWM's on PortD. one on PortD.5 (AVRTC0/AVRCH2) and PortD.3 (AVRTC2/AVRCHAN7). This is all laid out in the Help file and charts.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My experience of hpwm on 18f25k22 is from picaxe 28x2 and many modes,it can seem complicated,depending on abiity to decipher data sheet, which I lack.
I will have to see what happens to portd bits when I set dir as out and use pwmon as this is not clear to me with 328 which has portd marked as digital pwm on uno.
I will try all commands in the video but knowing the pic/avr channels/timer/ccp data will be a problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I will have to see what happens to portd bits when I set dir as out and use pwmon as this is not clear to me with 328 which has portd marked as digital pwm on uno.
PWMON for AVR clearly described in Help with example for mega328.
The HPWM AVR OCRnx example in Help shows exactly how to set the mega328 for all the available PWM's provided by GCB.
While defining the constants for the timers used (TCx) and the PWM channel (AVRChANx) may seem like a hassle, the program memory saved can be substantial, or essential in the case of smaller ATTinys. My overiding concern was that the HPWM library fit comfortably in say an ATTiny13a.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
PWMON for AVR clearly described in Help with example for mega328. Is that in demos in latest gcb - pwm solutions/avr command usage examples/
using demos in latest gcb - pwm solutions/avr command usage examples/mega328p-007 is using
'Set the PWM pin to output mode.
dir PortD.3 Out 'OC2B on D3
dir PortB.2 Out 'OC1B on D10
dir PortB.1 out 'OC1A on D9
dir PortD.5 Out 'OC0B on D5
this is intruiging as port b is used.
I tend to stick with 328 but haven't mastered it, like I stick to 18f25k22 because it's tidy and have a few but more complicated than using uno/nano with pickit needed..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Kent. Hope not. The files I posted are really test programs that I use and they may be useful to others - but, we cannot and should not create demos for everything.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I find the help doesn't explain everything sometimes. I try to use the demos (soutions) to help.
In this case dir portd out : pwmon - mega328 does what to portd and where is it explained?
If using dir portd.5 out and pwmon then could I use any other portd bits as output?
If not then if 2 port bits are output then which is used for pwm?..for non psychic users.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"In this case dir portd out : pwmon - mega328 does what to portd and where is it explained?"
PWMON for AVR in Help, what else is there to explain? only PortD.5 will have PWM.
"If using dir portd.5 out and pwmon then could I use any other portd bits as output?"
Yes all other pins available on PortD for general purpose I/O, although I think the UNO RX/TX PortD.0 and PortD.1 may be dedicated to the serial port.
"If not then if 2 port bits are output then which is used for pwm?..for non psychic users."
In the case of the UNO board with the mega328, I always refer to the UNO/PINOUT diagrams that can easily be found on the net, or barring that the actual datasheet. From there you can pair up OCOB, OC1A, OC1B, and OC2B HPWM output pins to the Port pins. The aforementioned HPWM example provides both Port pin and UNO pin cross reference for the mega328, easy peasy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If the 18F26K22 works then the 18F25K22 will work the same. Anyway, works in timer2 and 6. Tested CCP1, 2, 3, 4 and 5. You will get, on this device, double the frequency on some channels - set the config correctly to resolve this.
Works.
'Chip Settings
#chip 18F26K22, 64
DIR portc.2 Out 'CCP1
DIR portc.1 Out 'CCP2
DIR portc.6 Out 'CCP3
DIR portb.0 Out 'CCP4
DIR porta.4 Out 'CCP5
#define PWM_Timer2_Freq 28 'Set frequency in KHz, just change the value
#define PWM_Timer6_Freq 68 'Set frequency in KHz, just change the value
#define PWM_2_Duty 20
#define PWM_2_Clock_Source 2
#define PWM_5_Duty 30
#define PWM_5_Clock_Source 6
PWMOn (2) 'Will enable CCP/PWM channel
PWMOn (5) 'Will enable CCP/PWM channel
do
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Nice video, what is gcb pwm ?
Say I use a mega328 then pins with hpwm are portd and for legacy it's just
On a pic I guess it's pins with hardware pwm...like a 18f25k22 has 4 pwm pins.
On mega328 does that mean any portd pin set as out will have 38khz on it?
Moving on to next pwm in video..see image-the code shows dir portb out, not which port bit. typo?
Last edit: stan cartwright 2018-08-27
I will add the AVR constants info to the video. But, essentially the same two main control constants work and so does PWMOn for AVR.
pwmon/off is easier than setting ocr0,tccr0,wgm01 or other stuff to get pwm.
In the case of 18f25k22, looking at the data sheet doesn't say "these pins have hardware pwm", just timers and ccp modules.
In the image from the video, it says dir portb out. Why not portb bit no, as pics don't have whole ports that can be pwm like mega328?
With 328 ,is any port with pwm set as output going to have the same pwm signal on it?
It's not obvious. If the command was portx.xpwmon/off it would be.
Yes, if someone has time to improve then I am sure we can make AVR the same.
The 18f25k22 has two CCP/PWM channels. Numbered 4 and 5 with selected timers as 2, 4 or 6.
I think not. One PWM per Port on the AVRs
Pretty obvious. The parameter is the channel. Like 4=CCP4, 5=CCP5 etc etc. Noting that you could have a number being a CCP/PWM or a PMW module. It is all down to the device you are using. So, to get the correct parameter.... examine the datasheet... or do I as do... examine the 18f25k22.dat file and search for CCPXCON and/or PWMXCON as these will help you understand the capabilities
And, this wont be so obvious. Support ECCP. the datasheet masks this... see the datasheet for (E)CCP. The ECCP/PWM on the 18f25k22 (ECCP/PWM has been deprecated by Microchip) is something I have not personally tested but you can easily get working by setting the correct register(s)/bit(s) - but, it should work. ECCP/PWM is on channel 1, 2 or 3 on the 18f25k22.
With the AVR devices it is better to think of HPWM in terms of Timer/Counter numbers like TC0, TC1, and TC2 for the mega328. Each TCx represents a frequency independent PWM module. With GCB TC0 and TC2 can only have one PWM, while TC1 can have two PWM for the mega328 device. Large pinout devices like the mega2560 can have three PWM on TC1, TC3, TC4, and TC5.
When thinking of Ports, the mega328 can have two frequency independent PWM's on PortD. one on PortD.5 (AVRTC0/AVRCH2) and PortD.3 (AVRTC2/AVRCHAN7). This is all laid out in the Help file and charts.
My experience of hpwm on 18f25k22 is from picaxe 28x2 and many modes,it can seem complicated,depending on abiity to decipher data sheet, which I lack.
I will have to see what happens to portd bits when I set dir as out and use pwmon as this is not clear to me with 328 which has portd marked as digital pwm on uno.
I will try all commands in the video but knowing the pic/avr channels/timer/ccp data will be a problem.
PWMON for AVR clearly described in Help with example for mega328.
The HPWM AVR OCRnx example in Help shows exactly how to set the mega328 for all the available PWM's provided by GCB.
While defining the constants for the timers used (TCx) and the PWM channel (AVRChANx) may seem like a hassle, the program memory saved can be substantial, or essential in the case of smaller ATTinys. My overiding concern was that the HPWM library fit comfortably in say an ATTiny13a.
Bottom line is... I dont know how they did it.
CCP4 and CCP5 should work on portb.0 and porta.4 respectively. The ECCP may not work, so, dont try.
PWMON for AVR clearly described in Help with example for mega328. Is that in demos in latest gcb - pwm solutions/avr command usage examples/
using demos in latest gcb - pwm solutions/avr command usage examples/mega328p-007 is using
'Set the PWM pin to output mode.
dir PortD.3 Out 'OC2B on D3
dir PortB.2 Out 'OC1B on D10
dir PortB.1 out 'OC1A on D9
dir PortD.5 Out 'OC0B on D5
this is intruiging as port b is used.
I tend to stick with 328 but haven't mastered it, like I stick to 18f25k22 because it's tidy and have a few but more complicated than using uno/nano with pickit needed..
Do we need every trivial example code from Help committed to demo's?
@Kent. Hope not. The files I posted are really test programs that I use and they may be useful to others - but, we cannot and should not create demos for everything.
I find the help doesn't explain everything sometimes. I try to use the demos (soutions) to help.
In this case dir portd out : pwmon - mega328 does what to portd and where is it explained?
If using dir portd.5 out and pwmon then could I use any other portd bits as output?
If not then if 2 port bits are output then which is used for pwm?..for non psychic users.
"In this case dir portd out : pwmon - mega328 does what to portd and where is it explained?"
PWMON for AVR in Help, what else is there to explain? only PortD.5 will have PWM.
"If using dir portd.5 out and pwmon then could I use any other portd bits as output?"
Yes all other pins available on PortD for general purpose I/O, although I think the UNO RX/TX PortD.0 and PortD.1 may be dedicated to the serial port.
"If not then if 2 port bits are output then which is used for pwm?..for non psychic users."
In the case of the UNO board with the mega328, I always refer to the UNO/PINOUT diagrams that can easily be found on the net, or barring that the actual datasheet. From there you can pair up OCOB, OC1A, OC1B, and OC2B HPWM output pins to the Port pins. The aforementioned HPWM example provides both Port pin and UNO pin cross reference for the mega328, easy peasy.
and, for those following along at home...
If the 18F26K22 works then the 18F25K22 will work the same. Anyway, works in timer2 and 6. Tested CCP1, 2, 3, 4 and 5. You will get, on this device, double the frequency on some channels - set the config correctly to resolve this.
Works.