Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

P.W.M.///Duty Cycle help

Status
Not open for further replies.

D.M.

New Member
I am trying to make a very basic remote control... I have an infrared emitting LED and an IR detector.

Can someone explain how i can make different buttons activate the IR LED each with a certain duty cycle % so the IR detector can receive it and perform a function, in pseudo code?

I understand i need to utilize duty cycle but i dont quite see how i can control it..

I need a quick explanation as to how to utilize duty cycle or pulse width modulation.

thank you inadvance
 
I am trying to make a very basic remote control... I have an infrared emitting LED and an IR detector.

Can someone explain how i can make different buttons activate the IR LED each with a certain duty cycle % so the IR detector can receive it and perform a function, in pseudo code?

I understand i need to utilize duty cycle but i dont quite see how i can control it..

I need a quick explanation as to how to utilize duty cycle or pulse width modulation.

thank you inadvance

The duty cycle is how long the output is high compared to low.
For one signal just put the output on high for 10% of the time and off for 90%. For the next put it on 20% high and 80% low etc etc
 

BrownOut

Banned
A simple timer chip makes a good duty cycle generator. The duty cycle is typically set by two resistors. So, your controller may include a timer and an arrray of DPST switches to select a specific resistor pair for each command. This may not be an optimal solution, but we can come up with a rough design baised on it, unless someone has a better idea.
 
Last edited:

D.M.

New Member
I am using a PIC to try to implement this.

I understand what Nigel is saying about 10-90% 20-80% and 30-70%.. with that i can represent 5 functions. its a start..

I also understand duty cycle. the output will be high for a certain % of a period..

What i am thinking i need to do is... write code that updates a counter register each time the output is high on my IR LED. for example, i press button "1" and it turns my IR LED on with a duty cycle of 10%, or button "2" with a 20% duty cycle.

Then i need to have another snippet of code that will detect (with my IR detector) the pulse.
For remote controls the frequency of the signal is 36.7kHz, 38kHz, 40kHz, and 56.9kHz.


i have two questions:

1) does the frequency in which i transmit matter? (i am just trying to make a basic remote.)

2) how do the signals emitted from the IR LED get decoded? If i were to have a button transmit at 38kHz and 10% duty cycle, do i just set a register to count how many times the output was high over one period and from that divide by the clock frequency to get duty cycle % at the receiving end..

then would i have another snippet of code to say if "this duty %" then "this task"

I understand this may be vague, but i am relatively confused and need some guidance.

Again, Thanks in advance
 
Last edited:

phoenox

New Member
Sounds like you will need two seperate circuits. One for transmitter and one for reciever.

You can get a PIC with PWM output built in. I think this would be the easiest way to implement your transmitter.

If you are already set on a device that does not have a PWM peripheral --

Start_timer();

while(1)
{
PWM_out = 1;
while(timer < on_time){}
PWM_out = 0;
while(timer < period){}
timer = 0;
set_on_time(); // On time = period * duty cycle(%) / 100
}

Most(All?) PICs have timers built in that will work for this.

For the reciever:

Start_Timer();

while(PWM_in == 1){}
while(PWM_in == 0){}
timer = 0;

while(1)
{
while(PWM_in == 1){}
on_time = timer;
while{PWM_in == 0){}
period = timer;
timer = 0;
duty cycle = on_time * 100 / period;
Do_your_task(duty_cycle);
}

If you don't want your processer to sit around doing nothing all the time(while(){}) you can use interrupts instead.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top