View previous topic :: View next topic |
Author |
Message |
smiles
Joined: 20 Feb 2008 Posts: 33
|
pic16f88: Time equivalent to voltage |
Posted: Mon Mar 16, 2009 8:09 am |
|
|
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 ...
Thanks so much ! |
|
|
Ttelmah Guest
|
|
Posted: Mon Mar 16, 2009 8:21 am |
|
|
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
|
|
Posted: Mon Mar 16, 2009 1:31 pm |
|
|
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
|
|
Posted: Thu Mar 19, 2009 9:28 am |
|
|
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 |
|
|
|