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

pic16f88: Time equivalent to voltage

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

pic16f88: Time equivalent to voltage
PostPosted: Mon Mar 16, 2009 8:09 am     Reply with quote



Could you tell me is this thing possible, change the value of variable resistor and based on the voltage at pin RB0, we can set the time in seconds equivalently that another pin would be "ON" in that distance of time then "OFF"
for e.g, 5V ~ 20s, 4V ~ 15s ... Rolling Eyes
Thanks so much !
Ttelmah
Guest







PostPosted: Mon Mar 16, 2009 8:21 am     Reply with quote

What you draw can destroy the PIC.
You have 12v, flowing through a 220R resistor, when the switch is made, clamped to 5v, by the input protection diodes in the chip. Potentially (12-5)/220A flowing = 31.8mA
The maximum rating for the protection diodes is 20mA.
Think again...

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Mar 16, 2009 1:31 pm     Reply with quote

Second remark would be that in order to read the analog voltage you would have to connect it to a pin with A/D capabilities (pin AN1, AN2, AN3, ...).
smiles



Joined: 20 Feb 2008
Posts: 33

View user's profile Send private message

PostPosted: Thu Mar 19, 2009 9:28 am     Reply with quote

Thanks! I had changed the circuit and now I have
10 seconds ~ 4.2V
20 seconds ~ 3.5V
30 seconds ~ 3.16V
40 seconds ~ 2.88V
50 seconds ~ 2.6V
60 seconds ~ 2.23V

Here is what I try to do, a person will rotate the knob to choose the seconds that the bulb will "ON", when he presses the button, the program will first check the voltage value like above
Code:

setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
set_adc_channel(0);
adc_value = read_adc();
volts = (float)(adc_value*5)/1023.0;   
if (volts > 3.5)
time = 20;
//for e.g, I will calculate for the rest ...

When he releases the button then the bulb light on for (time) seconds (maybe I delay for 500ms and check again the AN0 pin to determine whether he released or not)
My circuit uses external 1MHz crystal (4us for one instruction), so for 1 second I have
Code:

setup_timer_2( T2_DIV_BY_4, 250, 10);
#int_timer2
void timer2_isr()
{
   i++;
   if (i==time)
   {
        //code to make the bulb "OFF"
   }
}

Now the problem here is that person can press button to stop the light when the time still not end yet, how can I detect that action ?
Thanks Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion 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