 |
|
 |
| Parallax Forums > Public Forums > BASIC Stamp > Stupid Newb Q: Need a ~20hz clock input | Forum Quick Jump
|
|  jmccorm Registered Member
        Date Joined Sep 2004 Total Posts : 16 | Posted 11/22/2005 8:38 PM (GMT -8) |   | I have a segment of code that needs to be run at regular intervals. Something close to 20 times per second is good. Unfortunately, because of the branching in the code, the run-length is not predictable, so I just can't insert a regular delay. Trying to time out multiple delays for the branches would not give me the precision I need.
I'm a good programmer, but an electronics idiot. Is there a low component count/cost way that I can get myself a ~20hz clock onto one of my pins? If an operation is necessary to clear the pin, that is fine.
I'm thinking some easy combination of resistors and capacitors might do it, but as I said, I'm an electronics idiot. I'd rather avoid a 555 chip if possible because I need to keep the component count low. (I've already crammed too many things onto my breadboard.)
The idea here is that I've got to take a button input, say, every 1/20th of a second (or an interval close to that... I don't care too much as long as it is REGULAR). That gets stored to an external eeprom. Later, it has to play it back with the exact timing it was recorded at.
Low end for recording would be 1/15th or so of a second. 1/50th of a second at the high end would be overkill but acceptable.
PSEUDOCODE FOR RECORD: While [ other activity is going on in support chip ] Wait for clock signal Clear clock if necessary Read byte from I2C EEPROM Read bit state from button Is the button in a different state than the bit that is recorded in a position in the EEPROM byte? If so, store the modified byte back to EEPROM End While
PSEUDOCODE FOR PLAYBACK: While [ other activity is going on in support chip ] Wait for clock signal Clear clock if necessary Read byte from I2C EEPROM Output nibble of byte to pins 12-15 End While | | Back to Top | | |
  |  jmccorm Registered Member
        Date Joined Sep 2004 Total Posts : 16 | Posted 11/23/2005 6:20 AM (GMT -8) |   | So.... the wiring would be something like this?
GROUND connects to one capacitor's lead The other capacitor lead connects to.... the 57k resistor?
The 57k resistor's other lead connects to my PIC IO pin and also to the 370 ohm resistor. The 370 ohm resistor's other lead connects to... ground? | | Back to Top | | |
  |  allanlane5 Registered Member

       Date Joined Aug 2004 Total Posts : 3675 | Posted 11/23/2005 7:50 AM (GMT -8) |   | This sounds like a job for the smT chip.
http://www.rhombus-tek.com/co-processors.html
This chip will generate a 50 mSec (20 Hz) signal, which you can then use to synchronize your BS2 program. It's only $12, it's an 8-pin DIP with resonator. It also has inside it a recieve only RS-232 port, which can be handy.
Check out their documentation for how to use this with a BS2 to provide simple multi-tasking. Very clever. | | Back to Top | | |
   |  Tracy Allen Registered Member

       Date Joined Jul 2004 Total Posts : 2962 | Posted 11/23/2005 10:26 AM (GMT -8) |   | Metron, while it is true there is a surge of current when p0 goes high in the circuit, about 80 milliamps, it only stays at that level for about 5 microseconds. The Stamp is quite robust, and the surge wll not create enough heating in the internal circuits of the Stamp to do damage. (famous last words?!) HOWEVER, you are right, in that it is a good idea to include the pin protection resistor of ~220 ohms to limit the initial current. This resistor is much lower value than the timing resistor, so it doesn't significanlly affect the charging.
220 370k p0 ---/\/\---o---/\/\---o--- Vss | | `----||----' 0.1 uf
Another way to do the charging with a single command, replace HIGH 0 : INPUT 0 with PWM 0,128,1 ' one cycle of PWM at 1/2 duty, leaves pin an input
BTW, the reason the initial current even without the 220 ohms is limited to around 80 milliamps is that the Stamp acts like it has internally a resistor of around 60 ohms, and that limits the initial current to 5/60 = 0.083 amp. The 5 microseconds comes from the time constant of 0.1uF with 60 ohms. Tracy Allen www.emesystems.com | | Back to Top | | |
 |  jmccorm Registered Member
        Date Joined Sep 2004 Total Posts : 16 | Posted 11/23/2005 11:01 AM (GMT -8) |   | You guys are awesome.
I've got it working. I put it into a loop and incremented a counter. I saw how long the counter got in 10 seconds, and sure enough, almost smack on 200. rctime gave me a value of 67956, which on a BS2P is 52ms. Very very nice.
Being able to clear the timer flag is great, and not having to worry about missing the flag (in case my code runs long) in these circumstances is also great. I went ahead and put in the protection resistor because, if for no other reason, I can be an electronics idiot, so extra protection is worth putting in there in case I end up shorting something.
The resistance that I settled on (trial/error) was 400k. The only note that I would add is that the "delay 1" between the HIGH and INPUT commands really does make a difference in the time. Looks like the capacitor just doesn't get drained in time running at BS2P speeds.
I'll be back with the completed piece in about 20 days! | | Back to Top | | |
 |  jmccorm Registered Member
        Date Joined Sep 2004 Total Posts : 16 | Posted 12/14/2005 6:08 PM (GMT -8) |   | | | |
| Forum Information | Currently it is Tuesday, February 09, 2010 3:18 AM (GMT -8) There are a total of 415,988 posts in 57,637 threads. In the last 3 days there were 78 new threads and 885 reply posts. View Active Threads
| | Who's Online | This forum has 18517 registered members. Please welcome our newest member, try388. 51 Guest(s), 7 Registered Member(s) are currently online. Details Rsadeika, Graham Stabler, humanoido, Bob Lawrence (VE1RLL), Rick Brooks, JohnandElspeth, mikestefoy |
Forum powered by dotNetBB v2.42EC SP2.02 dotNetBB © 2000-2010 |
|
|