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.

How to generate three frequency at a time with Timer0, Timer1, Timer2 ???

Status
Not open for further replies.

saifbd3344

Junior Member level 3
Joined
Apr 20, 2014
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Dhaka
Activity points
163
Dear,
I am using PIC16F690. I want to generate variable frequency PWM in background.
eg.
30khz for 10msec
45khz for 10msec
65 khz for 10msec
in while loop and in background. we can use other timer (Timer0, Timer1, Timer2) also so plz give me the suggestion to make it.
 

Hi,

Where exctely is the problem?

You should find the information on how to setup for 30kHz PWM frequency in datasheet.
How to setup for a desired duty cycle also.

Now you could count for 300 PWM cycles or use another timer to get your desired 10ms.

The same is with the other frequencies.

Klaus
 

I did a project where I wanted to generate frequencies and from memory I placed 256 values representing one cycle of a sine wave in memory. Then you set up one timer for the frequency you want times 256 and feed out the sine values starting from index 0 until index 255 and then back to 0.

Regards,
John.
 

didn't got your problem.

you want to generate 3 frequencies simultaneously using timer,,,... or you are using PWM mode (where you can directly set the duty cycle) or what??
 

didn't got your problem.

you want to generate 3 frequencies simultaneously using timer,,,... or you are using PWM mode (where you can directly set the duty cycle) or what??
I don't use any PWM. I just use timer0 and timer1. I am not sure where from I can got my solution. Can you tell just how to generate 3 frequency with one microcontroller? show me some example code please...::cry:
 

You can use this logic

Code:
void interrupt ()
{
if (TMRF1_bit==1 && PORTC.B1 ==1)
{ 
LATC.B4 = ~ LATC.B4;
}
 else if (TMRF1_bit==1 && PORTC.B2 ==1)
{ 
LATC.B4 = ~ LATC.B4;
}
else if (TMRF1_bit==1 && PORTC.B3 ==1)
{ 
LATC.B4 = ~ LATC.B4;
}
else 
{TMR1ON_bit==0;}

TMR1IF_bit==0;
TMR1H=0;TMR1F=0
}

void main()
{
// disable analog pins if microcontroller has
// set timer in 16 bit mode using T1CON register
// enable interrupts by setting INTCON register 
// set pins (PORTC.B1 , B2, B3) as input
// set pins PORTC.B4 as output

// 

do 
{ 
if(PORTB.B1==1)
{
  TMR1H =0; TMR1L=0; // put any other value as per your freq requirement
  TMR1ON_bit=1;
}
else if(PORTB.B2==1) // put any other value as per your freq requirement
{
  TMR1H =0; TMR1L=0xFF;
  TMR1ON_bit=1;
}
else if(PORTB.B3==1) 
{
  TMR1H =0xFF; TMR1L=0; // put any other value as per your freq requirement
  TMR1ON_bit=1;
}
else
TMR1ON_bit=0;

}
}


I don't have datasheet and compiler right now so I can't test it. most probably is it correct just try it.
(Change the port number and pin number according to your microcontroller)
You can make it more efficient with more programming concepts (remove or add some lines of code).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top