RC Timer with one pin

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have set up an rc timer using 2 pins with the charging pin through a diode to charge a capacitor. I have pin 4 set in the DDIR to 0 (input) and it works fine.

I want to charge the cap with pin4 as an output pin then change the DDIR to input and wate for the cap do discharge . It seems the discharge is immediate as the pin must sink the current during the changeover from input to output.

Is there a way to do this? I only have 6 pins on the Attiny12V

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why use a diode, or even two pins? Connect a single I/O pin via a resistor and capacitor to ground, that's it. Set the pin to source to charge the cap, wait at least 3-5 times the time constant then set the pin to sink and immediatly start polling the pin register of that I/O pin. You have to use fairly large resistor/capacitor values to get decent delay times.

-Curiosity may have killed the cat
-But that's why they have nine lives

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahhh shoot, I had my scope set wrong I have it working now, I know when I was using bascom it worked that way and working in assembler now I thought I was doing something wrong but I just had some wires messed up. I am using a 1uf cap and a 1k thermistor I get from 1.8ms at 32F and .2 ms at 100F now it's on to making a lookup table and output to the stepper for the final part of the project.

Thank's for the quick reply it can save me hours of head banging and I appreciate it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just keep in mind the resistor and capacitor values themselves will change with temperature as well, so ideally you want the resistor and capacitor to be thermally coupled if possible to avoid offset errors.

-Curiosity may have killed the cat
-But that's why they have nine lives

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

metron9 wrote:
I have set up an rc timer using 2 pins with the charging pin through a diode to charge a capacitor. I have pin 4 set in the DDIR to 0 (input) and it works fine.

I want to charge the cap with pin4 as an output pin then change the DDIR to input and wate for the cap do discharge . It seems the discharge is immediate as the pin must sink the current during the changeover from input to output.

Is there a way to do this? I only have 6 pins on the Attiny12V

I think so.
Just be sure that youdon't change the PORTx bit before the DDIRx bit so as to avoid outputting a low even for a few microseconds.

BTW its more typical to allow a cap to charge up and then discharge it with the port pin.