|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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? Last edited by DanL : 23-03-2004 at 20:17. |
|
#2
|
|||||
|
|||||
|
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
|
||||
|
||||
|
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?
![]() |
|
#4
|
|||||
|
|||||
|
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.
|
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||||
|
|||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Quote:
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
|
|||||
|
|||||
|
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 |
|
#9
|
||||
|
||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Quote:
I'm sure there're other threads that explain the fundamentals of PWM, PPM, and whatever else. |
|
#10
|
|||||
|
|||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Your right, that was a typo on my part.
|
|
#11
|
||||
|
||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Quote:
-Kevin |
|
#12
|
||||
|
||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Quote:
Quote:
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] 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) [ |
|
#13
|
|||
|
|||
|
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
|
||||
|
||||
|
Re: Fading LEDs using a PWM signal from the Edubot
Quote:
|
|
#15
|
|||
|
|||
|
Re: Fading LEDs using a PWM signal from the Edubot
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |