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

Trouble with manual PWM

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

Trouble with manual PWM
PostPosted: Wed Sep 26, 2007 2:31 pm     Reply with quote

I ran the following code on a LED but the led doesn't start from zero brightness and end at full brightness. I tried everything and I am running out of idees. Can somebody please advice why the Led doesnt start at zero brightness until full brightness.

[/double aan = 0;
double af=10000;
int i;
portb=0;
set_tris_a(all_in);
set_tris_b(all_out);

for (i =0;i<=100000;++i)
{
aan = aan+0.1;
af = af-0.1;
output_low(pin_b0);
delay_us(af);
output_high(pin_b0);
delay_us(aan);

}]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 26, 2007 2:39 pm     Reply with quote

Quote:
int i;
portb=0;
set_tris_a(all_in);
set_tris_b(all_out);

for (i =0;i<=100000;++i)

For starters, an 'int' in CCS is an unsigned 8-bit number.
It's not ANSI C. It can only hold a value of 0 to 255.

There is a very good chart in the latest CCS manual, which
shows the CCS data types and their range of values.
Download the manual here:
http://www.ccsinfo.com/downloads/CReferenceManual.pdf
The chart is on page 49 in the Acrobat reader.

All integer data types are 'unsigned' by default.
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Wed Sep 26, 2007 2:46 pm     Reply with quote

thanks. It seems to work.
Will this be equavalent to a normal PWM output on a port if I just fine tune the frequency?
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