View previous topic :: View next topic |
Author |
Message |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
PWM issues on 16F883 |
Posted: Mon May 30, 2011 12:53 pm |
|
|
Hi There,
I'm using PWM 1 & 2 on a PIC16F883 with 200kHz.
It seems to work somewhat but every 40ms I get a 40ms break where I don't have a pwm available on PIN_C2. So it's like as if a frequency (~11.74Hz) was overlayed on top of my pwm. Why is that?
Thank you for hints & suggestions!
See my sample app:
Code: |
#include <16F883.h>
#case
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
void main(void) {
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2( T2_DIV_BY_1, 24, 1);
set_pwm1_duty(13);
set_pwm2_duty(13);
while(1);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
[SOLVED] PWM issues on 16F883 |
Posted: Mon May 30, 2011 2:54 pm |
|
|
Uh, I was told that it just appears like this on the oscilloscope because of FFT with our Tektronix - I'll need to do some research on that to get refreshed.... |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19364
|
|
Posted: Mon May 30, 2011 3:05 pm |
|
|
No reason at all with the code as given....
Check with something not using the PWM. Just sit the code in a loop toggling this pin. Does this then work OK, or is the problem still there?. If the latter, you need to be looking at a hardware source. Something silly like noise on MCLR?.
What compiler version?.
Code: |
#include <16F883.h>
#case
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(clock=20000000)
void main(void) {
//setup_ccp1(CCP_PWM);
//setup_ccp2(CCP_PWM);
//setup_timer_2( T2_DIV_BY_1, 24, 1);
//set_pwm1_duty(13);
//set_pwm2_duty(13);
while(1) {
output_toggle(PIN_C2);
output_toggle(PIN_C1);
}
}
|
Won't be 200K, but won't be that far off!...
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Mon May 30, 2011 3:52 pm |
|
|
Well I couldn't do that in my real app, as said, this is just a little sample program to demonstrate the problem i'm experiencing. But as we've already figured out here, it's the Fast Fourier Transform of my Tektronix scope that gets "confused" - this error is not actually physically on my pic nor on the board. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19364
|
|
Posted: Tue May 31, 2011 1:56 am |
|
|
I posted before your reply appeared.
Old lesson 'know your tools'. Weird, have never seen anything like that on my Tektronix scopes, but presumably an oddity of your particular unit.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
cerr
Joined: 10 Feb 2011 Posts: 241 Location: Vancouver, BC
|
|
Posted: Tue May 31, 2011 9:41 am |
|
|
Ttelmah wrote: | I posted before your reply appeared.
Old lesson 'know your tools'. |
Yep, I fully agree! Ttelmah wrote: | Weird, have never seen anything like that on my Tektronix scopes, but presumably an oddity of your particular unit. |
No, it could happen on any digital oscilloscope as far as i know, it's just a matter of how the FFT is imoplemented. My device is the TDS 3012B dual channel scope. |
|
![](templates/subSilver/images/spacer.gif) |
|