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

GENERATING PWM USING THE TIMER

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



Joined: 11 Jan 2021
Posts: 7

View user's profile Send private message

GENERATING PWM USING THE TIMER
PostPosted: Fri Mar 04, 2022 12:27 am     Reply with quote

Hello everyone.
I want to generate pwm from this processor (PIC12F683) without using the ccp1 leg. I want to use the GP5(A5) pin for this operation. The electronic card circuit I have drawn does not allow other conditions. When I try to generate pwm with interrupt using timer, the while loop of my program starts to crash. While I am creating a continuous pwm signal, I want to operate comfortably in my while loop. I would be glad if you help. Thanks in advance.



Code:
#include <12F683.h>
#device ADC=10
#use delay(internal=8000000)


Code:
#include <main.h>
#FUSES NOMCLR                                         //MCLR = A3 pin
void main()
{
   setup_adc_ports(sAN2, VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   port_a_pullups(0x0A);
   set_tris_a(0x0E);
   output_a(0x00);                       
   while(TRUE)
   {
      if(input(pin_a3)==0)
      {
         output_high(pin_a1);
         delay_ms(1000);
         output_low(pin_a1);
      }
   }
}

_________________
@electsoftware
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 04, 2022 1:08 am     Reply with quote

Quote:

When I try to generate pwm with interrupt using timer, the while loop
of my program starts to crash.

Post your code for the timer interrupt. Post the code in main() that
enables it, and post the interrupt routine. You left that code out of
your posted program.

Quote:
port_a_pullups(0x0A);

Here, you think a weak pullup is enabled on pins A1 and A3.
But pin A3 doesn't have that ability. Look at this diagram on page 36:
REGISTER 4-4: WPU: WEAK PULL-UP REGISTER
It shows no pullup is available on pin A3 when using the NOMCLR fuse.
12F683 data sheet:
https://ww1.microchip.com/downloads/en/DeviceDoc/41211D_.pdf

Quote:
output_a(0x00);

This line sets all pins as outputs, unless you have a secret
#use fast_io(a) statement that you didn't post.
akin54



Joined: 11 Jan 2021
Posts: 7

View user's profile Send private message

PostPosted: Fri Mar 04, 2022 1:49 am     Reply with quote

Code:
#include <main.h>
#FUSES NOMCLR                                         //MCLR = A3 pin
#int_timer2
void timer2 ()
{
output_high(pin_a5);
delay_us(12);
output_low(pin_a5);
}
void main()
{
   setup_timer_2(T2_DIV_BY_1,1,1);
   setup_adc_ports(sAN2, VSS_VDD);
   setup_adc(ADC_CLOCK_DIV_2);
   port_a_pullups(0x02);
   set_tris_a(0x0E);
   output_a(0x0E);   
   enable_interrupts(INT_timer2) ;
   enable_interrupts(GLOBAL);
   while(TRUE)
   {
      if(input(pin_a3)==0)
      {
         output_high(pin_a0);
         delay_ms(1000);
         output_low(pin_a0);
      }
   }
}

_________________
@electsoftware
akin54



Joined: 11 Jan 2021
Posts: 7

View user's profile Send private message

PostPosted: Fri Mar 04, 2022 1:50 am     Reply with quote

Yes, now I see. I made the MCLR pin a hardware button.
_________________
@electsoftware
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