Pwmout on B.0 for 40X2

steliosm

Senior Member
Hello. I'm trying to figure out why I can't pulse a LED on B.0 using pwmout/pwmduty when I can turn it on and off without any issues. I tried looking at the command descriptions for any limitations but I didn't find anything relative. I am using the smd version of the 40X2 chip (vB.3).

Any ideas what I could test/check?

Thank you,
Stelios
 

PhilHornby

Senior Member
I haven't used the 40X2, but the PWMOUT wizard only allows for C.1 and C.2 on that processor.

Manual 1 describes B.0 as (In/Out/ADC12/hint0/SRI)

D.5,D.6 and D.7 are available for use with hpwm (never did get to the bottom of the difference), if that helps.

You might be able to steer PWM on B.0 - but that requires study of the datasheet for that PIC.

See also: https://picaxeforum.co.uk/threads/transfer-pwm-output-to-a-different-pin.32339/
 
Last edited:

inglewoodpete

Senior Member
While the 40X2 and 28X2 use very similar silicon, PWM on B.0 is only available in the 28X2. I checked the PIC18F4xK22 datasheet (DS41412F) and Table 14-10 shows that B0 is not associated with the "Standard PWM" function.

It MAY be possible to direct Standard PWM to any pin that can handle (E)CCP. Refer to Table 2 in the datasheet. These pins are identified as PxA-B-C. Having said that, I have never tried to redirect PWM in a K22, so I have never researched it and you could be on a steep learning curve!
 
Last edited:

AllyCat

Senior Member
Hi,
.. I tried looking at the command descriptions for any limitations but I didn't find anything relative. ...
The relevant part of the Command Description is quite clear: "1) The command only works on certain pins. ".

Unfortunately, the 40X2 appears to be a rather poor choice if you need PWM, because only a few pins have the "silicon" (on-chip) hardware to support PWM. I'm not an X2 user, but the 40X2 section (diagram) in PICaxe Manual 1 appears to indicate that only two pins (on port C) are available for PWM and four (on ports D/C) for "HPWM". The Base PIC Data Sheet seems to confirm this limitation and the chip has no "Alternate Pin Function" Registers; there are a few "(E)CCP" alternative connections marked in the "Pin Allocation Table" (on page 7) but they are marked as "CCP../P3A multiplexed in fuses." which are probably not available to the normal (on-chip) PICaxe programming process.

Cheers, Alan.
 

steliosm

Senior Member
I think I messed the pinouts somehow on the 40x2. I was under the impression that those pins had PWM support.
@PhilHornby you are right, the Wizards only shows 2 pins. Hpwm might be tha way to go enabling or disablign specific channels.
@inglewoodpete I breadboarded the circuit using a 28X2, I was planning to move to an smd version of 20X2 but due to space limitations I ended up using a 40X2 smd. Probably this is what messed up the pins I could use.
@AllyCat yes, the manual mentions that the command only works on certain pins :)

Thank you for your comments and suggestions!
 

AllyCat

Senior Member
Hi,
Hpwm might be the way to go enabling or disabling specific channels.
Yes, the terminology of {H}PWM often causes confusion. ALL the PWM commands need the relevant on-chip Hardware and the "H" in HPWM specifies an "H-Bridge" output, i.e. where the four outputs are inter-related. In principle, you can use any one, or a combination of pins, but only at the same PWM Frequency and related Pulse Duty Cycle. However, there may be some limitations if you wish to use any of the (unused) four pins for a different purpose.

Cheers, Alan.
 
Top