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

Using ECCP as PWM

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



Joined: 24 Feb 2004
Posts: 3

View user's profile Send private message ICQ Number

Using ECCP as PWM
PostPosted: Thu Mar 04, 2004 9:41 am     Reply with quote

Hi All...

Does anyone knows how to set ECCP to function as PWM just like what is been done to set PWM in CCP Module.

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 255, 1);
duty = 512;
set_pwm1_duty(duty);


Thanks and Regards
Ttelmah
Guest







Re: Using ECCP as PWM
PostPosted: Thu Mar 04, 2004 4:08 pm     Reply with quote

ericzuki wrote:
Hi All...

Does anyone knows how to set ECCP to function as PWM just like what is been done to set PWM in CCP Module.

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 255, 1);
duty = 512;
set_pwm1_duty(duty);


Thanks and Regards

The functions work just as normal, except there are some new options (look in the .h file for the chip you are using). The default 'CCP_PWM' setting, gives a single PWM output on P1A. To access the 'multiple output' modes, I ended up manually "OR'ing" the value for the setup with 0x40, to get the full bridge output (which you don't want/need).
The default (if the top two bits of CCP1CON are left '0'), is for the extended CCP module to behave largely like the standard module.

Best Wishes
valemike
Guest







PostPosted: Tue Jul 20, 2004 5:48 pm     Reply with quote

I'm about to try using the ECCP on the PIC18F458. I've seen some of you set a few bits to get it working beyond a standard PWM application.

With Full Bridge apps, a way to brake a motor is to short the two bottom FETs. I see that the ECCP does not provide this in the module's settings.

If i were to tear down ECCP, and reinitialize it as general I/O just for the purpose of turning on the two bottom fets in the H-bridge, can I run the risk of shoot-through while changing the TRIS registers?

Anyone who has done this, please chime in.
Thanks,
Mike
rickydee



Joined: 03 Oct 2004
Posts: 2

View user's profile Send private message

PostPosted: Sun Oct 03, 2004 2:09 pm     Reply with quote

I'm not able to get the ECCP1 pin working on a PIC18F458, but the CCP1 pin does work well.


setup_timer_2(T2_DIV_BY_1, 199, 1);

setup_ccp1(CCP_PWM);
set_pwm1_duty(25);

setup_ccp2(CCP_PWM);
set_pwm2_duty(25);

Anyone have an idea why?

Thanks,

Eric
MikeValencia



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

This function works fine for me...
PostPosted: Tue Oct 05, 2004 4:55 am     Reply with quote

Code:


#byte PIC_PR2       = 0xFCB
#byte PIC_ECCP1CON  = 0xFBA
#byte PIC_ECCPR1L   = 0xFBB
#byte PIC_ECCPR1H   = 0xFBC
#byte PIC_PIR1      = 0xF9E
#byte PIC_T2CON     = 0xFCA

#define PIC_PIR1_TMR2IF 0x02

[snip]


void setup_eccp(int direction)
{
    /* Disable ECCP1/P1A, P1B, P1C and P1D */
    latd=0xFF;
    set_tris_d(0xFF);
   
    /* Set PWM period by loading PR2 register */
    PIC_PR2 = 50;
   
    /* Set the PWM duty cycle by loading the ECCPR1L register and */
    /* ECCP1CON<5:4> bits. */
    PIC_ECCPR1L = 0x00;       // this keeps it off
     
    /* Configure ECCP1 module for */
    /* 1. PWM full bridge output forward */
    /* 2. Active LOW on all four fets */

    if (direction == DIRECTION_OPENING)
    {
        PIC_ECCP1CON = 0x4F;  // 0100 1111
    }

    else // direction = DIRECTION_CLOSING
    {
        PIC_ECCP1CON = 0xCF;
    }
   
    /* Configure and start timer 2. Use divide by 1 */
    /* Clear timer2 interrupt flag bit */
    PIC_PIR1 &= ~PIC_PIR1_TMR2IF;
   
    /* Set TMR2 prescale value by setting 1:0 */
    PIC_T2CON = 0x00;  /* same as por values? */
   
    /* Turn on Timer 2 */
    PIC_T2CON |= 0x04;
   
    /* Enable PWM outputs after a new cycle has started */
    /* Wait for TMR2 overflow */
    while (!(PIC_PIR1 & PIC_PIR1_TMR2IF))
    {
        /* wait */
    }
   
    /* Now clear the TRISD bits */
    set_tris_d(0x0F);   
}
vitorego



Joined: 18 Apr 2006
Posts: 3

View user's profile Send private message

PostPosted: Thu Apr 20, 2006 5:54 am     Reply with quote

but this code works if i compile in CCS, and how i change duty cycle of 4 PWM? Itīs same way (set_pwmx_duty(value)).
And PWM frequency is define by timer 2 is that right?
Ttelmah
Guest







PostPosted: Thu Apr 20, 2006 8:24 am     Reply with quote

Set_pwmx_duty, supports up to pwm5 on chips that support it. For chips with the ECCP, Timer2, or Timer4, can be selected to feed the PWM. For compilers late enough to support this, it is in the manual...

Best Wishes
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