CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with PWM and PIC16F1619

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dmendesf



Joined: 31 Dec 2005
Posts: 32

View user's profile Send private message

Problem with PWM and PIC16F1619
PostPosted: Thu Jan 05, 2017 8:26 am     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 8:39 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 9:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 9:15 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 10:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 10:32 am     Reply with quote

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... :(
Confused
dmendesf



Joined: 31 Dec 2005
Posts: 32

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 10:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 12:01 pm     Reply with quote

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 support@ccsinfo.com
dmendesf



Joined: 31 Dec 2005
Posts: 32

View user's profile Send private message

PostPosted: Thu Jan 05, 2017 12:07 pm     Reply with quote

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 support@ccsinfo.com
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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