View previous topic :: View next topic |
Author |
Message |
buAliSina
Joined: 02 Nov 2010 Posts: 8
|
Generating PWM , Problem |
Posted: Wed Nov 03, 2010 7:28 pm |
|
|
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) {} ;
}
|
_________________ Just a dead body ignores Human suffering |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 04, 2010 12:12 pm |
|
|
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
|
Help |
Posted: Thu Nov 04, 2010 12:42 pm |
|
|
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
|
|
Posted: Thu Nov 04, 2010 12:57 pm |
|
|
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
|
thanks |
Posted: Thu Nov 04, 2010 1:13 pm |
|
|
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
|
|
Posted: Thu Nov 04, 2010 1:21 pm |
|
|
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
|
prob exists |
Posted: Fri Nov 05, 2010 1:46 pm |
|
|
Hi,
I did that way, nothing on oscilloscope. _________________ Just a dead body ignores Human suffering |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 05, 2010 2:11 pm |
|
|
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
|
Weird |
Posted: Fri Nov 05, 2010 4:17 pm |
|
|
hi,
LED blinked with no error !!! (as i knew it ) ;
_________________ Just a dead body ignores Human suffering |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 05, 2010 4:25 pm |
|
|
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
|
<> |
Posted: Fri Nov 05, 2010 4:48 pm |
|
|
Blinked with no problem ; _________________ Just a dead body ignores Human suffering |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Nov 05, 2010 4:58 pm |
|
|
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
|
Worked |
Posted: Fri Nov 05, 2010 5:40 pm |
|
|
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
|
|
Posted: Fri Nov 05, 2010 6:11 pm |
|
|
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 ? |
|
|
|