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

Why the function #USE pwm () does not work correctly

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



Joined: 17 Sep 2017
Posts: 59

View user's profile Send private message

Why the function #USE pwm () does not work correctly
PostPosted: Wed Nov 22, 2017 1:05 am     Reply with quote

Hi, I wrote the following program to create a wave pwm by activating the c7 pin on the pin output a2.
The wave is generated correctly, but when I deactivate the c7 pin, the output voltage level of the pin a2 is one.
This is while I want it to be zero.
I used disable_level=low, but again when off the pwm, the output level of the a2 pin is one.
Code:

#include <16f1829.h>
#device *=16
#fuses HS             //High speed Osc (> 4mhz for PCM/PCH)
#fuses NOWDT            //NO Watch Dog Timer
#fuses PUT            //Power Up Timer
#fuses NOLVP          //No low voltage programing
#fuses NOCPD          //No EE protection
#fuses NOPROTECT      //Code not protected from reading
#fuses NOWRT          //Program memory not write protected
#fuses NODEBUG        //No Debug mode for ICD
#fuses NOBROWNOUT     //No brownout reset
#USE DELAY (crystal=11059200)

#USE pwm(OUTPUT=PIN_A2,timer=2,FREQUENCY=500Hz,DUTY=99,disable_level=low)

#include <stdio.h>
#include <string.h>

void main()
{
set_tris_c(0b11111111);
set_tris_a(0b11111011);

while(TRUE)
  {
   if(input(PIN_C7)==1)
     {
      pwm_on();
     }
   if(input(PIN_C7)==0)
     {
      pwm_off();
     }
  }
}

Thank you for answering.
Ttelmah



Joined: 11 Mar 2010
Posts: 12826

View user's profile Send private message

PostPosted: Wed Nov 22, 2017 2:13 am     Reply with quote

When you turn the PWM off, it is disconnected from the pin.
The ECCP peripheral does support being overridden to a level. The CCP doesn't. You are using CCP3, which is a standard CCP.

Simply set the idle level on the pin. This then determines what appears when the PWM is turned off.
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