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

PWM 16F685 Problem

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 05, 2007 1:00 am     Reply with quote

With respect pin to C5, it's behaving correctly for the Full Bridge mode.
It's the P1A pin in that mode. According to Figure 11-6 in the 16F685
data sheet, pin C5 will be either a constant high or a constant low,
depending upon whether you're going in forward or reverse.
So pin C5 is OK.


There is a note in Section 11.5 of the data sheet (PWM Enhanced mode).
It says:
Quote:
The TRIS register value for each PWM output must be configured appropriately.

However, the ASM code generated by the compiler doesn't do this.
It only sets pin C5 as a low-level output pin. It leaves the other pins
(C2, C3, C4) in the default state, which is as input pins.

Here's something you could try. Add a line of code after each
setup_ccp1() function, to manually force pins C2-C5 to be outputs.
Add the lines shown in bold below.
Quote:

#include <16F685.h>
#fuses XT,NOWDT,BROWNOUT,PUT
#use delay (clock=4000000)

//=================================
void main()
{

// Setup the ECCP for PWM in full bridge mode.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
setup_timer_2(T2_DIV_BY_1, 255, 1);

set_pwm1_duty(100);


// Switch the H-Bridge outputs between forward
// and reverse every 5 seconds.
while(1)
{
// Run forward for 5 seconds.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
delay_ms(5000);

// Run in reverse for 5 seconds.
setup_ccp1(CCP_PWM_FULL_BRIDGE_REV | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
delay_ms(5000);
}

}

Then compile it and program it. Then when it's running, look at pin C2
in forward mode, and pin C4 in reverse mode. You should see PWM
pulses on them.
geshsoft



Joined: 01 May 2007
Posts: 14
Location: California

View user's profile Send private message

PostPosted: Sat May 05, 2007 2:14 am     Reply with quote

Thanks, this worked Very Happy
Why was not the compiller setting the TRIS registers anyways? I thought that this is the advantage of the standard io... Confused
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