|
|
View previous topic :: View next topic |
Author |
Message |
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
PIC18F2431 RB5(PWM4) not working |
Posted: Fri Jun 27, 2014 10:52 pm |
|
|
Hello everyone,
I am using pic18f2431 to generate 6 channel pwm. All pwm channels are working great except PWM4 (RB5). I know RB5 has PGM thingy & for that i have set the FUSE NOLVP.
Other operations can be performed on this pin RB5 (ie toggle, low, high) but no success in getting PWM on this RB5 pin.
I have tried on 5 other PICs, all are behaving same.
Load on RB5 Pin: Oscilloscope Probe
Programmer: PICKIT3 ICSP
PCWHD version: 4.105
Code: |
#include<18F2431.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP
#use delay(clock=40MHz , crystal)
#define PWM4 PIN_B5
void main()
{
set_tris_b (0x00);
setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_OFF);
setup_power_pwm(PWM_FREE_RUN, 1, 0, 999, 0, 1 ,0);
while(True)
{
set_power_pwm4_duty(1500);
output_toggle(PWM4); //
delay_ms(500);
}
}
|
|
|
|
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
|
Posted: Sat Jun 28, 2014 9:57 am |
|
|
Tried on a Brand new PIC18F2431 same issue.
changed the Programmer PICKIT3 to WINPIC800 same issue
it runs perfect in Proteus but in Hardware no success.
PWM0 ==> OK
PWM1 ==> OK
PWM2 ==> OK
PWM3 ==> OK
PWM5 ==> OK
PWM4 ==> DEAD (RB5) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sat Jun 28, 2014 11:30 am |
|
|
I'd suspect your compiler version is not configuring the power PWM properly.
It is a very old version.
V4, first started to work at all reasonably around 4.070, then had some quite 'troubled' versions around the low 4.100's.
However:
To override the pin when the PWM is in use, you should use the output override function, not directly write to the port.
Add the PWMPIN fuse, and the polarity bits, to program the pins to wake up driven to an idle state. Otherwise you risk problems if the drivers start up driving in 'conflict' with one another. So
PWMPIN, HPOL_LOW, LPOL_HIGH
Programs the 'high' pins low, and the low pins 'high' at boot-up.
Your clock settings are impossible. The maximum _crystal_ frequency supported by the chip, is 25MHz (1A in data sheet). To run at 40MHz, requires a 10MHz crystal, and the PLL, or an external oscillator. You are also selecting the internal RC oscillator at the same time as selecting a crystal.
Specify the clock division in the setup. Otherwise it may change with compiler versions. |
|
|
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
|
Posted: Sat Jun 28, 2014 12:33 pm |
|
|
Code: |
#include<18F2431.h>
#fuses NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP, NODEBUG, PWMPIN, HPOL_HIGH, LPOL_LOW
#use delay(clock=20MHz , crystal)
void main()
{
set_tris_b (0x00);
setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_COMPLEMENTARY,PWM_OFF);
setup_power_pwm(PWM_FREE_RUN | PWM_CLOCK_DIV_4, 1, 0, 999, 0, 1 ,0);
while(True)
{
set_power_pwm4_duty(500);
delay_ms(500);
}
}
|
Still no success |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sat Jun 28, 2014 12:57 pm |
|
|
As I said, probably the compiler version is not configuring it correctly.
Run the code up in MPLAB.
Use it's simulator, and run it to the point where the PWM has been configured.
Read the values in the configuration registers, and see what they contain, versus what the data sheet says they should contain.
Haven't got 4.105 (it was one I didn't keep, because it had problems). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jun 28, 2014 4:02 pm |
|
|
There is a difference between vs. 4.105 and 5.026. In your version,
Config Word 3 is set to 0x8030, but in 5.026, it's set to 0x9d30.
Add the line shown in bold below, in that exact position. Re-compile,
program, and test. See if it now works.
Quote: | #include<18F2431.h>
#fuses NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP, NODEBUG, PWMPIN, HPOL_HIGH, LPOL_LOW
#rom 0x300004 = {0x9d30}
|
The 18F2431 data sheet says this about the PWM4MX bit and other bits
in the the Config3H byte:
Note 1: Unimplemented in PIC18F2331/2431 devices; maintain this bit set. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|