CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

3W RGB flashlight project

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Arizona Chris



Joined: 20 Dec 2014
Posts: 69
Location: Arizona

View user's profile Send private message Visit poster's website

3W RGB flashlight project
PostPosted: Sat Oct 08, 2016 3:21 pm     Reply with quote

How bout that, a project that has nothing to do with robotics. ;) This started when I found I had three 12F675 processors left in my drawers, and I had to design a project to use them up. I now use a modern new 8 pin device, and the old reliable '675 proved its worth again on this.

What this does is you vary the voltage on a potentiometer output from 0-5v into the analog input, A0. Then generate a PWM at a 1khz period from zero (fastest is actually around 20uS) to 100% on. Three of these are on the PCB, and control one leg of a 3W RGB led.

This was a real fun project! and I cant tell you how cool it is to go out in the dark at night with this thing and blast various colors out and about with the brightness of a supernova.

Before I post the code for one '675 at the end, please see the write up for more complete information:

The entire project write up can be found here:

This project was a lot of fun, and in the dark outside at night is a blast! 3W does not sound like much light, but it is as if the sun rose and was in your hand. It was very interesting to illuminate various plants and rocks with the different colors and see how the appearance greatly changed. Its like a whole nother universe of seeing the world has opened up for me. Here is the write up:

http://www.schursastrophotography.com/PICprojects/RGBflashlight.html

All our PIC projects coded in CCS-C can be found here by the way:

http://www.schursastrophotography.com/PICCmain.html

Thanks for looking!

Code:

//****************************************************************************
//Chris Schur
//Project Name here: 12F675 NO xtal LED PWM
//Date: 9/23/16
//****************************************************************************

/*Description of this Program: This program Will use the 100k pot and vary the
PWM out put from near zero on time to near 100% on time at a pulse period of
1ms. Works great!*/

//I/O Designations ---------------------------------------------------
// A0 (GPIO0): An0 = Potentiometer Input
// A1 (GPIO1): X (An1)
// A2 (GPIO2): Digital Output to LED
// A3 (GPIO3): X (can ONLY be input)
// A4 (GPIO4): X (An3)
// A5 (GPIO5): X

//--------------------------------------------------------------------

//Include Files:
#include <12F675.h> //Normally chip, math, etc. used is here.
//Directives and Defines:

#device ADC=10 //This directive will only work if put RIGHT HERE first...

#fuses NOPROTECT,NOMCLR
#use delay(internal=4MHz)
#use fast_io(A)

//****************************************************************************
//-- Main Program
//****************************************************************************

void main(void) {

// Set TRIS I/O directions, define analog inputs, comparators:

set_tris_A(0b101001); //sets port directions

//(analog inputs digital by default)
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_DIV_2);
set_adc_channel(0);

//Initialize variables and Outputs: --------------------------------------

int16 result; //0 - 1023 out of ADC
int16 on_pulse; //LED high pulse width in uS
int16 off_pulse;

//----------------------------------------------------------------

//MAIN LOOP:

while (true) {

//First read ADC
result = read_adc(); //0 - 1023

//calculate pulse width:
on_pulse = (result); //for a range of 0 to 1023uS
off_pulse = (1023 - on_pulse);


//next send pulse to servo output:

if (on_pulse > 20) { //The fastest you can on off is like 20us. so we do this

output_high(PIN_A2); //LED out = 1
delay_us(on_pulse); //high time
output_low(PIN_A2); //turn off pulse

delay_us(off_pulse); //remainder of 1ms PWM pulse max

} //if

} //while

} //main
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group