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
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

Generating PWM , Problem
PostPosted: Wed Nov 03, 2010 7:28 pm     Reply with quote

Hi , wrote this code but nothing comes out !!!! driving me mad plz help
Code:

#include <16F628A.h>
#FUSES NOWDT, INTRC, NOPUT, NOPROTECT, NOBROWNOUT, MCLR, NOLVP, NOCPD
#use delay(clock=4000000)

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,49,1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(40);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

   while (TRUE) {} ;

}


Mad
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 12:12 pm     Reply with quote

1. What is your compiler version ?

2. What is your testing environment ?
a. Proteus ?
b. Factory manufactured development board ?
c. Home-built board ?
d. 3M breadboard ?

3. Have you ever made this PIC do anything, such as blinking an LED ?
In other words, do we know that that PIC, the board, and the compiler
are basically working, and the problem is only with PWM ?


Last edited by PCM programmer on Thu Nov 04, 2010 12:47 pm; edited 2 times in total
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

Help
PostPosted: Thu Nov 04, 2010 12:42 pm     Reply with quote

hi thanks for reply

1. version CCS 4.084 PCWH
2. both Proteus and home-build board ( that i know its ok )
3. blinking LED works fine , but the problem is PWM signal
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 12:57 pm     Reply with quote

I took your posted code, with no changes, and compiled it with vs. 4.084.
I ran it on a 16F628A on a PicDem2-Plus board. I looked at pin B3 with
an oscilloscope and I see negatives pulses, about 10 us duration, with
a high time of about 40 us. The oscilloscope's built-in frequency counter
says 19.75 KHz. It's working. The PIC is running at +5v.

Here's the top of the generated .LST file:
Code:

CCS PCM C Compiler, Version 4.084, xxxxx       04-Nov-10 11:50

               Filename: pcm_test.lst

               ROM used: 50 words (2%)
                         Largest free fragment is 1998
               RAM used: 6 (3%) at main() level
                         6 (3%) worst case
               Stack:    0 locations
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

thanks
PostPosted: Thu Nov 04, 2010 1:13 pm     Reply with quote

thanks a million , worked on it for 3 days and no result

whats your suggestion ?

thanks again for spending time to help me .
_________________
Just a dead body ignores Human suffering
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 04, 2010 1:21 pm     Reply with quote

Quote:
whats your suggestion ?

Does it still not work for you ?

If so, remove all external circuits on pin B3. Just look at the pin
with an oscilloscope.
buAliSina



Joined: 02 Nov 2010
Posts: 8

View user's profile Send private message

prob exists
PostPosted: Fri Nov 05, 2010 1:46 pm     Reply with quote

Hi,

I did that way, nothing on oscilloscope.
_________________
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 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