Joined: 30 Aug 2007 Posts: 144 Location: South Africa
Trouble with manual PWM
Posted: Wed Sep 26, 2007 2:31 pm
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
Posted: Wed Sep 26, 2007 2:39 pm
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
Posted: Wed Sep 26, 2007 2:46 pm
thanks. It seems to work.
Will this be equavalent to a normal PWM output on a port if I just fine tune the frequency?
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