Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SOFT PWM For MikroC For PIC PIC12F675

Status
Not open for further replies.

asking

Full Member level 5
Joined
Sep 21, 2010
Messages
279
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Activity points
3,377
Hello friends,

I have small application of Generating 38KHZ Frequency for IR Application. I want to use PIC12F675 and it doesn't have Hardware CCP Module inside the micro controller so i want to use Soft PWM For generating PWM Signal. I searched PIC Library but i m not able to find the Soft PWM library code so please guide me how to use Soft Library for PWM Generation.

Thanks
 

you can use any one of timer from controller and to create freq on perticlar pin just toggle this pin.
but you will get 50% duty cycle.
to use variable duty cycle you have to program in software.
first make 1 this pin use nop's then 0 this pin in isr only.
 

you can use any one of timer from controller and to create freq on perticlar pin just toggle this pin.
but you will get 50% duty cycle.
to use variable duty cycle you have to program in software.
first make 1 this pin use nop's then 0 this pin in isr only.

can you provide me some more details about Soft PWM ? using Timers and interrupts ?

Thanks
 

Code:
void interrupt()
{
  if (INTCON.TMR0IF ==1) // timer 0 interrupt flag
  {
    GPIO = ~GPIO;      // Toggle PORTB bit0 LED
    INTCON.TMR0IF = 0;         // clear the flag
    INTCON.TMR0IE = 1;         // reenable the interrupt
    TMR0 = 204;           // reset the timer preset count
  }

}



// code starts here...
void main()
{

  // setup portb to show the interrupts by blibking LEDs
  TRISIO = 0;    // PORT is all output...to show the interrupts
  GPIO = 0;       // start with all outputs low
  ANSEL = 0;

//Timer0 Registers Prescaler= 1 - TMR0 Preset = 204 - Freq = 38461.54 Hz - Period = 0.000026 seconds
OPTION_REG.T0CS = 0;  // bit 5  TMR0 Clock Source Select bit...0 = Internal Clock (CLKO) 1 = Transition on T0CKI pin
OPTION_REG.T0SE = 0;  // bit 4 TMR0 Source Edge Select bit 0 = low/high 1 = high/low
OPTION_REG.PSA = 1;   // bit 3  Prescaler Assignment bit...0 = Prescaler is assigned to the WDT
OPTION_REG.PS2 = 0;   // bits 2-0  PS2:PS0: Prescaler Rate Select bits
OPTION_REG.PS1 = 0;
OPTION_REG.PS0 = 0;
TMR0 = 238;             // preset for timer register


// Interrupt Registers
  INTCON = 0;           // clear the interrpt control register
  INTCON.TMR0IE = 1;        // bit5 TMR0 Overflow Interrupt Enable bit...1 = Enables the TMR0 interrupt
  INTCON.TMR0IF = 0;        // bit2 clear timer 0 interrupt flag
  INTCON.GIE = 1;           // bit7 global interrupt enable


  while(1)  //endless loop
  {
  }
}

But i m getting 9.13KHZ Maximum Frequency on 12F675, i tested with DS0201 Oscilloscope.

Please do needful. I am Running 12F675 with internal Oscillator 4 MHZ. and i want 38KHZ to drive IR led for TSOP1838.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top