View previous topic :: View next topic |
Author |
Message |
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
Problem with PWM and PIC16F1619 |
Posted: Thu Jan 05, 2017 8:26 am |
|
|
Hi, i´m trying to setup PWM with this PIC. It uses PIN MUX and I think I made some mistake. My CCS version is 5.066
I´m running from internal oscillator at 16MHz:
Code: | #use delay(internal=16000000,restart_wdt) |
Selected PIN_C0 as PWM output:
Code: | #pin_select CCP1OUT = PIN_C0 |
I´ve chosen CCP1:
Code: |
setup_timer_2(T2_DIV_BY_4,63,1); //51,2 us overflow, 51,2 us interrupt
setup_ccp1(CCP_PWM|CCP_TIMER2);
set_pwm1_duty(131); |
And... pin stays at 1 :(
Any ideas? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Thu Jan 05, 2017 8:39 am |
|
|
lots... but please post your COMPLETE program, it's necessary as our crystal balls all got busted on New Years Eve.
Rule #1 on this forum is to post a small, compilable,cutandpasteable program showing your problem. That way we can quickly cut/paste/compile/test on our systems and get back to you fast!
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Jan 05, 2017 9:04 am |
|
|
However:
set_pwm1_duty(131L);
Note the 'L'. Otherwise you are running the PWM in 8bit mode, and the output will be permanently on with this value.... |
|
|
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Thu Jan 05, 2017 9:15 am |
|
|
Hi Jay.... here´s a sample program... main.c:
Code: | #include <main.h>
void main()
{
setup_timer_2(T2_DIV_BY_4,63,1); //51,2 us overflow, 51,2 us interrupt
setup_ccp1(CCP_PWM|CCP_TIMER2);
set_pwm1_duty(131L);
while(TRUE)
{
}
} |
and main.h:
Code: | #include <16F1619.h>
#fuses NOBROWNOUT,NOCLKOUT,NOIESO,NODEBUG,NOLVP,NOWDT,INTRC_IO
#use delay(internal=16000000,restart_wdt)
#pin_select CCP1OUT = PIN_C0 |
I already fixed the "L" issue but the problem persists. Thanks for your help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Jan 05, 2017 10:29 am |
|
|
Though not the problem, your period is not what you think.
16Mhz/4 = peripheral clock
4MHz/4 = Timer2 clock
1Mhz/64 = PWM frequency = 15625Hz
64uSec period.
Hopefully you don't intend to try to use the interrupt at this sort of frequency. If so, around 1/4 of your processor's time will be used just getting into and out of the interrupt. You'll be interrupting every 256 instructions... |
|
|
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Thu Jan 05, 2017 10:32 am |
|
|
Seems I found it. setup_ccp1 appears not to be working on this chip. I changed
Code: | setup_ccp1(CCP_PWM|CCP_TIMER2); |
to:
Code: | #pin_select CCP1OUT = PIN_C6
#byte CCP1CON = 0x293
#byte CCPTMRS = 0x29e
SET_TRIS_C( 0x00 );
CCP1CON = 0x8c;
CCPTMRS = 0x00; |
And now I have a working PWM at pin_c6 (i´ll change now to pin_c0 and see if it keeps working). How can I report back this to CCS? I´ve chosen this processor because it´s used in the curiosity board so in my mind it would be well debugged... :(
|
|
|
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Thu Jan 05, 2017 10:49 am |
|
|
Hi Ttelmah, thanks for this reminder. I plan to use the PID Math Accelerator to control the PWM duty (I´ll probably do the debug of this entire chip to CCS :D ) I also tried my code with PIN_C0 and it worked... so PIN MUX is working. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 05, 2017 12:01 pm |
|
|
Quote: | How can I report back this to CCS ? |
At the top of this forum, it says:
Quote: | CCS does not monitor this forum on a regular basis.
Please do not post bug Reports on this forum. Send them to [email protected] |
|
|
|
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Thu Jan 05, 2017 12:07 pm |
|
|
Done.... let´s see how fast they fix it.
PCM programmer wrote: | Quote: | How can I report back this to CCS ? |
At the top of this forum, it says:
Quote: | CCS does not monitor this forum on a regular basis.
Please do not post bug Reports on this forum. Send them to [email protected] |
|
|
|
|
|