I am trying to do use the Soft PWM on the 12F508 but not making much progress.
I have seen the other post in this forum about the couple of bugs where you need to change the 2 lines in stdbasic.h and you need bracket around the 3 parameters, and I have made these changes.
I have the following lines...
#define PWM_Out1 GPIO.1
dir GPIO out
Which I think should set up a channel on the pin 6 of the PIC as an output, is that correct?
Assuming it is, is it still possible to do...
PWM_Out1 = ON
and
PWM_Out1 = OFF
to set the pin high or low?
Finally, I'm rather at a loss with what to set the 3rd parameter to, I've found the formula, and I've just found the page in the help with the formula and the other about the constants, but...not making much sense of it.
What has really thrown me is even if the above is wide of the mark, why is pin 4 of my 508 high all the time now and it never used to be?
Thanks
Tom
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Pin 4 (GPIO.3) is the MCLR pin, which is an input with a pullup resistor to Vdd (necessary for programming). This basically reduces GPIO.3/MCLR pin to push button input or Non Return to Zero data lines, like the Dallas One Wire protocol.
'This is a program example for the GCBasic soft PWM function
#chip 12F509, 4
#config _INTRC_OSC
#define PWM_Out1 GPIO.0
#define PWM_Out2 GPIO.1
#define PWM_Out3 GPIO.2
dir GPIO b'001000' 'GPIO.3 is MCLR
Main:
For incrPWM = 1 to 255
PWMOut(1, incrPWM, 1) 'channel 1, duty cycle, number of cycles
PWMOut(2, incrPWM, 1) 'channel 2
PWMOut(3, incrPWM, 1) 'channel 3
Next
For decrPWM = 255 to 1
PWMOut(1, decrPWM, 1)
PWMOut(2, decrPWM, 1)
PWMOut(3, decrPWM, 1)
Next
wait 20 10ms
goto Main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In a strict sense, the GPIO port direction needs to be setup, as GCBasic doesn't do so by default, like the midrange devices.
If PWM_Out1 is defined as your GPIO.1 (pin 6), then PWM_Out1 could be manipulated in any manner you wish, just try it out. Looking at the assembler, all the PWM_Out1(2,3,4,)'s are cleared upon exit from the soft PWM subroutine.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evening All
I am trying to do use the Soft PWM on the 12F508 but not making much progress.
I have seen the other post in this forum about the couple of bugs where you need to change the 2 lines in stdbasic.h and you need bracket around the 3 parameters, and I have made these changes.
I have the following lines...
#define PWM_Out1 GPIO.1
dir GPIO out
Which I think should set up a channel on the pin 6 of the PIC as an output, is that correct?
Assuming it is, is it still possible to do...
PWM_Out1 = ON
and
PWM_Out1 = OFF
to set the pin high or low?
Finally, I'm rather at a loss with what to set the 3rd parameter to, I've found the formula, and I've just found the page in the help with the formula and the other about the constants, but...not making much sense of it.
What has really thrown me is even if the above is wide of the mark, why is pin 4 of my 508 high all the time now and it never used to be?
Thanks
Tom
Here is a bare bones soft PWM example.
Pin 4 (GPIO.3) is the MCLR pin, which is an input with a pullup resistor to Vdd (necessary for programming). This basically reduces GPIO.3/MCLR pin to push button input or Non Return to Zero data lines, like the Dallas One Wire protocol.
'This is a program example for the GCBasic soft PWM function
#chip 12F509, 4
#config _INTRC_OSC
#define PWM_Out1 GPIO.0
#define PWM_Out2 GPIO.1
#define PWM_Out3 GPIO.2
dir GPIO b'001000' 'GPIO.3 is MCLR
Main:
For incrPWM = 1 to 255
PWMOut(1, incrPWM, 1) 'channel 1, duty cycle, number of cycles
PWMOut(2, incrPWM, 1) 'channel 2
PWMOut(3, incrPWM, 1) 'channel 3
Next
For decrPWM = 255 to 1
PWMOut(1, decrPWM, 1)
PWMOut(2, decrPWM, 1)
PWMOut(3, decrPWM, 1)
Next
wait 20 10ms
goto Main
Thanks for you prompt reply.
OK, so you don't need to define direction, which I guess is kind of obvious, you can't have a Soft PWM input.
Do you happen to know whether the instruction...
PWM_Out2 = ON
...if added to your code would send ping 6 high, or is that kind of instruction illegal if configured as a Soft PWM channel?
Tom
In a strict sense, the GPIO port direction needs to be setup, as GCBasic doesn't do so by default, like the midrange devices.
If PWM_Out1 is defined as your GPIO.1 (pin 6), then PWM_Out1 could be manipulated in any manner you wish, just try it out. Looking at the assembler, all the PWM_Out1(2,3,4,)'s are cleared upon exit from the soft PWM subroutine.