View previous topic :: View next topic |
Author |
Message |
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
PWM problem 16F1503 |
Posted: Wed Aug 31, 2016 1:03 am |
|
|
I would like to have an PWM output on Pin C5, so I declared PWM1 in the software, but I don't get PWM on this pin.
I've copied the program from PCM programmer from this topic:
http://www.ccsinfo.com/forum/viewtopic.php?t=48643&highlight=16f1503
This is my test program:
Code: |
#include <16F1503.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
//=========================================
void main()
{
setup_pwm1(PWM_ENABLED | PWM_OUTPUT | PWM_ACTIVE_HIGH);
setup_timer_2(T2_DIV_BY_1, 249, 1);
set_pwm1_duty(500L);
while(1);
} |
Why isn't it working? Should be simple...
Compiler version: 5.058 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Aug 31, 2016 1:49 am |
|
|
I'd suggest priorities....
Table 11-5.
You will see that CWG1A, and CLC1 both have higher priorities than the PWM. You need to ensure these are disabled. Now, technically the CLC1 output should default to A2, but don't trust it.
So:
Code: |
#include <16F1503.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4M)
//=========================================
void main(void)
{
setup_clc1(CLC_DISABLED);
setup_cwg(CWG_DISABLED, CWG_NO_AUTO_SHUTDOWN, 0 , 0);
setup_pwm1(PWM_ENABLED | PWM_OUTPUT | PWM_ACTIVE_HIGH);
setup_timer_2(T2_DIV_BY_1, 249, 1);
set_pwm1_duty(500L);
while(TRUE)
;
}
|
Haven't got a chip to test, but generally this is the commonest problem. Obviously you have MCLR enabled with your fuses so do need a pullup on this or the chip won't run. |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Wed Aug 31, 2016 2:03 am |
|
|
I had seen the MCLR fuse also, and change it to NOMCLR. Also updated to CCS version 5.062.
Tested your program, but unfortunately doesn't work also.
I've also added setup_oscillator(OSC_4MHZ); in my test program, but also this doesn't make sense. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Aug 31, 2016 2:09 am |
|
|
Have you tested the chip actually is running?.
A simple 'flash an LED' program?.
Always the first place to start. |
|
|
mvanvliet
Joined: 02 Jun 2009 Posts: 123 Location: The Netherlands
|
|
Posted: Wed Aug 31, 2016 3:29 am |
|
|
An output toggle function on pin A5 is working, but not on the C5 (even if I disable the setup_PWM/Setup_timer_2/Set_pwm_duty functions).
I've also tried an different PCB, with the same result.
edit: It is working, my fault, measuring PWM at the wrong pin. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Wed Aug 31, 2016 6:17 am |
|
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Aug 31, 2016 8:22 am |
|
|
re:
Quote: | edit: It is working, my fault, measuring PWM at the wrong pin. |
WELCOME to the 'club' ! It gets worse the older you get and the more pins the PIC has.....
..then there's those 'programmable' pins that 'magically' aren't what you thought they were....
Jay |
|
|
|