Go to Post Mentors learn from, are inspired by, and emulate each other. A team with a great lead mentor leads to a productive, inspired, and ultimately successful group of mentors. - Jared Russell [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 23-03-2004, 08:37
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
Fading LEDs using a PWM signal from the Edubot

[Edit]
For quick subject indexing purposes, this thread is turning into a discussion on timers and the use of custom PWM signals on the PIC18F8520
[/Edit]

A while ago, some of you may remember this thread where I presented an idea for a neat little car tachometer hack. I never really got around to finishing this, but for my high tech class, the opportunity has come up to make a demonstration of microcontrollers. I decided that it would be interesting to use the Edubot (both because of simplicity and familiarity) to create the tachometer hack mentioned in that thread.

Writing the code to gather the input signal and find the frequency (and thus, the RPM) is no problem for me. As for driving the LEDs, it was mentioned that the proper way is to use a PWM signal, just like was done for the IR beacons this year. Eventually I'm going to ask for help about using perhaps this IC (again, mentioned in the previous thread), but I don't really have time to learn about all the I2C bus stuff for this project. Instead, I have some questions about the PWM code used in this year's IR beacons.

First, can the Edubot generate a PWM signal with a frequency fast enough for the blink not to be 'detected' by the human eye? When I attached a status LED to this year's IR beacon, a flicker was recognized, much like some people can detect the 70-75Hz flicker of computer monitor.

Second, has there been a writeup explaining the custom PWM code used for the IR beacons? Specifically, I'd like to know how to adjust the duty cycle and frequency to create the best 'fade' effect possible.

Any of you advanced programming gurus have any suggestions?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies

Last edited by DanL : 23-03-2004 at 20:17.
  #2   Spotlight this post!  
Unread 23-03-2004, 11:37
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Fading LEDs using a PWM signal from the Edubot

Check User_Initialization(), step 5. there is an option (at least in the FRC) to set some pins up as custom.
  #3   Spotlight this post!  
Unread 23-03-2004, 13:08
CrashZero's Avatar
CrashZero CrashZero is offline
Computer Nerd
#1352 (Huskie Robotics)
Team Role: Programmer
 
Join Date: Mar 2004
Location: Stratford Northwestern
Posts: 44
CrashZero will become famous soon enoughCrashZero will become famous soon enough
Question Re: Fading LEDs using a PWM signal from the Edubot

I will gladly help but I am not sure just what you are trying to do. Are you trying to make the LED's blink fast enough that human eyes cannot detect it or do you want it to be slower so that it can be detected?
__________________
This is our world now... the world of the electron and the switch, the beauty of the baud. We make use of a service already existing without paying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals. We explore... and you call us criminals. We seek after knowledge... and you call us criminals. We exist without skin color, without nationality, without religious bias... and you call us criminals. You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals. Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for. I am a hacker, and this is my manifesto. You may stop me, but you can't stop us all...

quote from:

+++ The Mentor +++
  #4   Spotlight this post!  
Unread 23-03-2004, 14:06
Andrew Rudolph's Avatar
Andrew Rudolph Andrew Rudolph is offline
Git 'em!
no team (Robot in 3 Days)
Team Role: Mentor
 
Join Date: May 2001
Rookie Year: 2000
Location: Orlando, FL
Posts: 921
Andrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond reputeAndrew Rudolph has a reputation beyond repute
Send a message via AIM to Andrew Rudolph
Re: Fading LEDs using a PWM signal from the Edubot

He wants to use the EDU bot to dim the leds, a common way to dim leds is to have them blink. so he wants it to blink fast enough so it just appears as the led is dim.
__________________
iR3 Creative Engineering
Robot in 3 Days

FTC 6323 The Pink TeamMentor
FTC 8996 Pink Fluffy BunniesMentor
FRC 233 The Pink Team Mentor
FRC 1902 Exploding Bacon Mentor
  #5   Spotlight this post!  
Unread 23-03-2004, 15:25
CrashZero's Avatar
CrashZero CrashZero is offline
Computer Nerd
#1352 (Huskie Robotics)
Team Role: Programmer
 
Join Date: Mar 2004
Location: Stratford Northwestern
Posts: 44
CrashZero will become famous soon enoughCrashZero will become famous soon enough
Unhappy Re: Fading LEDs using a PWM signal from the Edubot

Ok i think that I understand what you want now, and I don;t think that I know a way to get it to do that. Sorry.
__________________
This is our world now... the world of the electron and the switch, the beauty of the baud. We make use of a service already existing without paying for what could be dirt-cheap if it wasn't run by profiteering gluttons, and you call us criminals. We explore... and you call us criminals. We seek after knowledge... and you call us criminals. We exist without skin color, without nationality, without religious bias... and you call us criminals. You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it's for our own good, yet we're the criminals. Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for. I am a hacker, and this is my manifesto. You may stop me, but you can't stop us all...

quote from:

+++ The Mentor +++
  #6   Spotlight this post!  
Unread 23-03-2004, 15:40
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Fading LEDs using a PWM signal from the Edubot

Dan,

This can be done using the PIC's dedicated PWM hardware. Have a look at the beacon code and note where the 40KHz duty cycle is set to 50%. You can get the effect you want by changing this value. The beacon drive circuit can be used to drive an array of LEDs too. If this isn't clear, I'll write some example code and post it.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #7   Spotlight this post!  
Unread 23-03-2004, 15:52
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Fading LEDs using a PWM signal from the Edubot

Quote:
Originally Posted by SuperDanman
First, can the Edubot generate a PWM signal with a frequency fast enough for the blink not to be 'detected' by the human eye? When I attached a status LED to this year's IR beacon, a flicker was recognized, much like some people can detect the 70-75Hz flicker of computer monitor.
Why not measure it and see?

The IR beacons aren't simple PWM signals. They are driven with short bursts of high-frequency pulses. The bursts repeat at a rate low enough that you can perceive as a flicker.

I don't know what the PWM frequency is, but I'd be very surprised if it were slow enough to detect with your eyes.
  #8   Spotlight this post!  
Unread 23-03-2004, 17:03
NoRemorse's Avatar
NoRemorse NoRemorse is offline
FOCUS Integration, LLC - Owner
AKA: Brian Roberts
FRC #1023 (Bedford Express)
Team Role: Alumni
 
Join Date: Feb 2003
Rookie Year: 2003
Location: Bedford
Posts: 221
NoRemorse has a spectacular aura aboutNoRemorse has a spectacular aura about
Send a message via AIM to NoRemorse Send a message via MSN to NoRemorse
Re: Fading LEDs using a PWM signal from the Edubot

PWM = pulse width modulation

its a serious of I's ans O's, and the higher the number, thr more of accurance of I's

the duty cycle is the total length between 2 leading edges
__________________

http://LSJBuildUp.com -Documenting the build of my LSJ, as well as other influential cars.
  #9   Spotlight this post!  
Unread 23-03-2004, 17:12
FotoPlasma FotoPlasma is offline
\: |
no team
 
Join Date: Jul 2001
Rookie Year: 2001
Location: San Jose
Posts: 1,900
FotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond reputeFotoPlasma has a reputation beyond repute
Send a message via AIM to FotoPlasma
Re: Fading LEDs using a PWM signal from the Edubot

Quote:
Originally Posted by NoRemorse
PWM = pulse width modulation

its a serious of I's ans O's, and the higher the number, thr more of accurance of I's

the duty cycle is the total length between 2 leading edges
The duty cycle is measured as a percentage of the total period of the square wave. You can also describe this as time between the rising edge and the falling edge of the square wave. I don't think that "the total length between 2 leading edges" was concise enough.

I'm sure there're other threads that explain the fundamentals of PWM, PPM, and whatever else.
__________________
I played hacky sack with Andy Baker.

2001-2004: Team 258, The Sea Dawgs
2005: Team 1693, The Robo Lobos
  #10   Spotlight this post!  
Unread 23-03-2004, 17:39
NoRemorse's Avatar
NoRemorse NoRemorse is offline
FOCUS Integration, LLC - Owner
AKA: Brian Roberts
FRC #1023 (Bedford Express)
Team Role: Alumni
 
Join Date: Feb 2003
Rookie Year: 2003
Location: Bedford
Posts: 221
NoRemorse has a spectacular aura aboutNoRemorse has a spectacular aura about
Send a message via AIM to NoRemorse Send a message via MSN to NoRemorse
Re: Fading LEDs using a PWM signal from the Edubot

Your right, that was a typo on my part.
__________________

http://LSJBuildUp.com -Documenting the build of my LSJ, as well as other influential cars.
  #11   Spotlight this post!  
Unread 23-03-2004, 17:41
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: Fading LEDs using a PWM signal from the Edubot

Quote:
Originally Posted by NoRemorse
...the duty cycle is the total length between 2 leading edges
Actually, the amount of time between successive edges of the same type (i.e., rising or falling) is the period. One divided by the period is the frequency. Duty cycle, usually expressed as a percentage, is the amount of time the pulse is high divided by the total period.

-Kevin
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #12   Spotlight this post!  
Unread 23-03-2004, 19:27
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
Re: Fading LEDs using a PWM signal from the Edubot

Quote:
Originally Posted by Alan Anderson
I don't know what the PWM frequency is, but I'd be very surprised if it were slow enough to detect with your eyes.
You can't detect it precisely (the human eye notices flashes of light only to about 25Hz-30Hz - coincidentally the framerate of television). However, some people can observe a flicker. Take your computer CRT - those are usually 70-75Hz. The problem with CRTs is this flicker can be detected and the subconcious detection of this flicker is one of the reasons prolonged exposure to a monitor leads to eye strain. The flicker is especially noticable from the corner of your eyes because the light detecting cells on the edges of the human eye are more sensitive to light vs. dark while the cells in the middle of the human eye are more sensitive to color. Proof: ever been stargazing and see a dim star in the corner of your vision but when you center your vision on it, it disapears? The corner of your vision is more sensitive to contrast while the center is more sensitive to color (if you think about this from an evolutionary standpoint, this also makes sense - our ancestors would have benefited from detecting moving objects in the corners of their vision). Anyways, the point of this extended tangent is that yes, the blinking is too fast to detect outright, but some people can observe the flicker much like the flicker of a computer monitor is observed.

Quote:
Originally Posted by Kevin Watson
Dan,

This can be done using the PIC's dedicated PWM hardware. Have a look at the beacon code and note where the 40KHz duty cycle is set to 50%. You can get the effect you want by changing this value. The beacon drive circuit can be used to drive an array of LEDs too. If this isn't clear, I'll write some example code and post it.

-Kevin
Okay, so I've examined the use of timers with the help of your beacon code and interrupt template from kevin.org... however, I still have some questions
Code:
// initialize timer 2, which generates the 40KHz IR carrier frequency
	PR2 = PWM_TOTAL_PERIOD;		// set PWM frequency (defined in beacon.h) [154]
	TMR2 = 0;					// clear timer2 register [142]	
	T2CONbits.T2OUTPS0 = 0;		// setup 1:1 postscale [141]
	T2CONbits.T2OUTPS1 = 0;
	T2CONbits.T2OUTPS2 = 0;
	T2CONbits.T2OUTPS3 = 0;
	T2CONbits.T2CKPS0 = 0;		// setup 1:1 prescale [141]
	T2CONbits.T2CKPS1 = 0;
	T2CONbits.TMR2ON = 1;		// start timer 2 [141]
So, with a 1:1 prescale, one timer tick is 1e-7 seconds, 100 ns. Assuming PWM_TOTAL_PERIOD is 250, that means the timer rollover handler is called every 25e-6 seconds, or 25 microseconds. 1 / 25e-6 results in the 40KHz frequency described in the comment. I can now see how to use a timer to generate the interrupt frequency needed. However, I don't see how this is used to generate the PWM signal

Code:
beacon.h:
// This sets the PWM high period, which should be 
// half of PWM_TOTAL_PERIOD for a 50% duty cycle.
// Set to 10000000*desired_high_period.
#define PWM_HIGH_PERIOD 125

beacon.c:
	// initialize PWM 1, which generates type 0 beacon waveforms
	TRISCbits.TRISC1 = 0;		// make sure CCP2/PWM1 is setup as an output [110]
	CCPR2L = PWM_HIGH_PERIOD;	// set CCP2/PWM 1 duty cycle (defined in beacon.h) [
I don't see any information about what CCPR2L is, or what timer 2 is used for. My problem is I found where you initialized timer 2 to create a 40KHz pulse, but I'm not seeing how it goes about creating the signal. What does timer 2 do (I don't see any interrupt handling routine)? What is CCPR2L and how does that relate to a duty cycle?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #13   Spotlight this post!  
Unread 23-03-2004, 21:44
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Fading LEDs using a PWM signal from the Edubot

There is some information in the IFI default code about how to enable a user PWM, along with assigning a duty cycle, etc. The rest of the information is in the PIC datasheet on Microchip's website.
  #14   Spotlight this post!  
Unread 23-03-2004, 22:23
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
Re: Fading LEDs using a PWM signal from the Edubot

Quote:
Originally Posted by steven114
There is some information in the IFI default code about how to enable a user PWM, along with assigning a duty cycle, etc. ...
Any hints on where? ;-)
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #15   Spotlight this post!  
Unread 23-03-2004, 22:46
steven114 steven114 is offline
Programming Wizard and Team Captain
AKA: Steven Schlansker
FRC #0114 (Eaglestrike)
Team Role: Programmer
 
Join Date: Feb 2004
Location: Los Altos, CA
Posts: 335
steven114 is a jewel in the roughsteven114 is a jewel in the roughsteven114 is a jewel in the rough
Send a message via AIM to steven114
Re: Fading LEDs using a PWM signal from the Edubot

http://www.microchip.com/download/li...x20/39609b.pdf
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tether for new EduBot Controller gburlison Programming 9 18-12-2003 17:53
pwm 13-15 wayne 05 Programming 2 04-10-2003 12:08
PWM and burning out motors patrickrd Technical Discussion 7 19-06-2003 15:30
Loss of signal in PWM cables. archiver 2001 6 23-06-2002 23:29


All times are GMT -5. The time now is 21:09.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi