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

Generating PWM , 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: Fri Nov 05, 2010 2:11 pm     Reply with quote

There may be a hardware problem with your PIC board, or your PIC.
Your programmer may not work.

Try the following simple program that blinks an LED on Pin B0.
Try to make this program work:
Code:

#include <16F628A.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP
#use delay(clock=4000000)

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

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }



Here is a schematic that shows how the LED and series resistor should
be connected to the PIC:
Code:

pin      330 ohms      LED       
B0  -----/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

Weird
PostPosted: Fri Nov 05, 2010 4:17 pm     Reply with quote

hi,

LED blinked with no error !!! (as i knew it ) ;

Crying or Very sad
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 05, 2010 4:25 pm     Reply with quote

Change the program to use pin B3. This is the PWM output pin. See if
you can blink an LED on pin B3. Example:
Quote:

#include <16F628A.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP
#use delay(clock=4000000)

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

while(1)
{
output_high(PIN_B3);
delay_ms(500);
output_low(PIN_B3);
delay_ms(500);
}

}
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

<>
PostPosted: Fri Nov 05, 2010 4:48 pm     Reply with quote

Confused

Blinked with no problem ;
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 05, 2010 4:58 pm     Reply with quote

Try this program. I tested it right now, with vs. 4.084. It worked.
It made the LED light up on pin B3. The oscilloscope shows a 50%
duty cycle squarewave, with a frequency of 244 Hz:
Code:

#include <16F628A.h>
#fuses INTRC_IO, NOWDT, PUT, NOLVP
#use delay(clock=4000000)

//==========================
void main()
{
setup_timer_2(T2_DIV_BY_16, 255, 1);
setup_ccp1(CCP_PWM);
set_pwm1_duty(128);

while(1);


If this doesn't work, my suggestion is to re-install the CCS compiler.
If that doesn't help, then get a new PIC. Maybe try a different PIC,
such as a 16F877, or something else.
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

Worked
PostPosted: Fri Nov 05, 2010 5:40 pm     Reply with quote

hi,


Worked ! but whats the dif ?

it was 50% DC ( and i'm not sure about freq )

plz tell me about freq ( i'm tired of calculating ! )

and the dif between our codes r just PUT as you see what do you think ?
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 05, 2010 6:11 pm     Reply with quote

The reason I chose the lowest possible frequency for hardware PWM
(244 Hz with a 4 MHz crystal) for my latest example was that I began to
suspect that maybe your board or your equipment has a problem with
frequency response or measuring.

Maybe your oscilloscope doesn't work over 500 Hz ?
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