View previous topic :: View next topic |
Author |
Message |
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
[SOLVED] Setting '1' as PWM value works intermittently |
Posted: Fri Mar 19, 2010 5:31 pm |
|
|
Hi, I made a simple program for my application, where I need constant 1us pulses at 5kHz and when I hit a button duty cycle is set to 50%.
If I write "set_pwm2_duty(1);" I get a really nice 1us pulse, but the problem is that it outputs about 14 pulses and then it outputs nothing for some time (I measured between 3ms and 10ms, but it looks random) and so on. If I put a high value for the duty, like "set_pwm2_duty(100);", the PWM works ok and I don't see any interruption. If I put an on-off on a pin in the main while loop, I see a constant frequency output so the cpu is not resetting itself.
The PIC is a 16F886 with a 20mhz crystal.
Does anyone have similar problems? How can I solve this?
Thanks
Here are the scope traces:
detail of the pulse train
a bunch of pulse groups
Here is the source:
main.c
Code: |
#include "C:\Programmi\PICC\Projects\Synrad PWM\main.h"
void main()
{
long duty = 1;
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_4,249,1);
setup_ccp2(CCP_PWM);
set_pwm2_duty(0);
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
//enable_interrupts(INT_RTCC);
//enable_interrupts(INT_AD);
//enable_interrupts(GLOBAL);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
set_pwm2_duty(1);
while(1);
}
|
main.h
Code: |
#include "C:\Programmi\PICC\Devices\16F886.h"
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear pin enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV21 //Brownout reset at 2.1V
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
Last edited by gip_mad on Sat Mar 20, 2010 4:29 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 19, 2010 5:46 pm |
|
|
1. Is this being tested on real hardware, or is this a Proteus project ?
2. What is your compiler version ?
3. What external circuits are connected to the CCP2 pin ? |
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Fri Mar 19, 2010 5:54 pm |
|
|
Thank you for the quick reply.
I'm testing this on real hardware, a pickit 28 pin demoboard and I have only the scope connected (Rigol DS1052E). I cut the track to the on board 32khz crystal.
Compiler version is 4.057.
Regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 19, 2010 6:10 pm |
|
|
I installed vs. 4.057 and programmed your code into a 16F886 on
a PicDem2-Plus board. I then ran it and looked at the CCP2 pin
with an oscilloscope. I see a short pulse, at a 5.000 KHz rate.
The signal looks clean. I don't see any noise pulses between the
short PWM pulses.
MPLAB reports this as the 16F886 silicon rev:
Quote: |
Target Device PIC16F886 found, revision = Rev 0x2
|
|
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Fri Mar 19, 2010 6:30 pm |
|
|
Wow. Just wow. That was fast. Thank you.
I have the same revision, 0x2. Can you suggest some tests I can do? Tomorrow I'll try ccp2, then maybe a different device, then a breadboard... then another oscilloscope. I'm going to bed, it's 1:28 am here and I risk burning up something if I'm tired.
Thank you again. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 19, 2010 6:32 pm |
|
|
I can't do any more hardware work on this until Sunday maybe. |
|
|
gip_mad
Joined: 23 Aug 2008 Posts: 24 Location: Italy
|
|
Posted: Sat Mar 20, 2010 4:28 am |
|
|
It turned out to be an oscilloscope issue. It happens when I use the "normal" mem depth.
I'm going to ask for clarification to forum where they talk about Rigols.
Thank you very much for your time.
Best regards |
|
|
|