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 CCS Technical Support

[SOLVED] Setting '1' as PWM value works intermittently

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

[SOLVED] Setting '1' as PWM value works intermittently
PostPosted: Fri Mar 19, 2010 5:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 5:46 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 19, 2010 5:54 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 6:10 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 19, 2010 6:30 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 19, 2010 6:32 pm     Reply with quote

I can't do any more hardware work on this until Sunday maybe.
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

PostPosted: Sat Mar 20, 2010 4:28 am     Reply with quote

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
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