Jump to content

RobG

Members
  • Content Count

    3,117
  • Joined

  • Last visited

  • Days Won

    248

Everything posted by RobG

  1. Right on the money Doc. In addition to those external influences, crystals can be made of different materials (typically quartz,) material itself can be cut different ways, and in case of 32kHz crystal, material is also cut in to a tuning fork shape. All of those can affect wake-up time. 32kHz crystals are the ones that take longest. And here's a quote from the book mentioned earlier (pg 34):
  2. I was simply telling you the quickest way to find an answer and believe me, I have seen so many post like "what pin is timer out connected to?" Quick search of User's Guide for "crystal" yields the following: Meaning it must be a lot longer than 50us. And Google...
  3. Looks good to me. To capture position, you can basically do what you have done before with i, maybe just use int or long instead. Declare i, for example unsigned int i = 1000; // middle position then replace // moving right with i++; and // moving left with i--;
  4. Quadrature encoders are pretty common these days, though most of us don't even realize we are using one, car radios, receivers, musical equipment, just FYI As OCY already suggested, you are not getting the full resolution here. If you have inputs to spare, I suggest connecting two pins together (for each port) and setting one to rising and one to falling edge. P1IN & 0x01 will test bit 0 of port 1, P2IN & 0x01 will test bit0 of port2, so //port 2 interrupt routine if(P1IN & 0x01) { //input high //moving left } else { //moving right } P2IFG &= ~0x01; //port 1 interrupt routine if(P2IN & 0x01) { //input high //moving right } else { //moving left } P1IFG &= ~0x01; If you decide to add falling edge, you will have to also test the port that has triggered interrupt. //port 2 interrupt routine direction = (P2IN & 0x01) ^ (P1IN & 0x01) // we only need to test one pin as both are connected together if(direction) { //moving left } else { //moving right } P2IFG &= ~(0x01 + 0x02) // but we need to clear flags for both, I am assuming we are using P2.0 and P2.1 //port 1 interrupt routine direction = (P2IN & 0x01) ^ (P1IN & 0x01) if(direction) { //input high //moving right } else { //moving left } P1IFG &= ~(0x01 + 0x02) // assuming we are using P1.0 and P1.1 Also, I think your drawing is not correct, A and B should be fixed in relation to each other, just shifted. In the lower drawing, A and B are not in the same position as in the upper drawing. If you want to implement it on a single port, all you need to do is add another conditional that will test flags and determine which pin triggered interrupt: //port 1 interrupt routine aOrB = P1IFG & 0x01 // port 1.0 is A, port 1.1 is B, so if P1IFG & 0x01 is true it must be A, otherwise we assume it's B that requested IF, unless we have more ports in use, then we will have to also test P1IFG & 0x02, and so on.
  5. RobG

    timer

    Start timer for 30sec. Watch for interrupt on port. If there is an interrupt, reset timer or do whatever. When timer expires. Turn off. Go to deep sleep. Another port interrupt can turn on and reset the timer and the cycle continues. See my IR Remote Control example, it's pretty much what you need.
  6. I suggest reading spec sheet and family user guide, it's all there.
  7. Keep in mind, and I think someone has already mentioned it, that phototransistor is analog. So if you connect it to digital input with simple pull up resistor, it will work in darkness with strong IR source. For example, in dark transistor is not conducting, your Vout is close to Vcc. Then you point strong IR at it and it's resistance is close to zero, your Vout is close to GND. All is good and your interrupts work as expected. Now go outside and introduce ambient light and weak IR light, your transistor is partially conducting, so your Vout is for example ~2V, weak IR will only cause small changes, Vout is ~1.8V. As you can see, those levels are not logic levels, so you need to bias and amplify Vout, then convert to digital levels using comparator or something else. You may also use second IR detector to detect changing ambient light or some combination of low pass filter and comparator. Also, I think IR diode is better suited for this as it has more linear output vs. light intensity, it's better suited for situations with ambient light and weak light sources. Phototransistor is more of a switch thing, light-on, dark-off. But that's just my opinion. EDIT: Check this out: http://books.google.com/books?id=sHV0c5 ... &q&f=false Something like in fig 10.7 or 10.9, where one diode will be pointed at your IR source and one just to the side of it.
  8. Ha, ha, yeah, I really need the rest, or test my changes before posting. Since switchReady is int, we need to either change it (and the switchStatus) to char unsigned char switchReady = 0; // when BITn is 0, means switch is unstable H->L or L->H unsigned char switchStatus = 0; // pressed or released or change if statement if(switchReady == 0xFFFF) As I wrote before, I had that code in another project where I used 16 switches and full USISR register (hence int) but in my if statement I only needed few of them tested. Not sure what you mean by misconceptions about de-bouncing though. Again, as I wrote before, this is just an example of how it could be done. Someone might have a requirement to scan every 5ms, or use switches that have long bounce time, or that all switches must be in sync. I wish I had more time to elaborate and make some drawings, but I think we can leave it at that. Is it perfect, no, is it needed for this particular example, probably not, it can be removed.
  9. No you didn't. Constructive critique is always a good thing, that's how we learn. I would probably reuse that piece over and over and then I would be surprised why stuff doesn't work. And I would assume that my code is fine. That's why we should have peer reviews. 73 Rob
  10. Rob, doesn't (11111110 & 0xFF) == true (non-zero result)? Am I messing up my "&" and "&&" logic? In the PIC Simulator I'm using, the result is "true"... You are correct, it should be if(switchReady == 0xFF) I was reusing this bit from my other project where I was masking some higher bits, only some were used for switches. if((switchReady & 0x3F) == 0x3F) Another good catch! I am getting sloppy or just need some rest.
  11. Here's my version of expanding LP to breadboard
  12. Could this have something to do with the inverting of USISRL you have proposed earlier? The only thing that should be changed is switchStatus = USISRL to switchStatus = ~USISRL switchReady = ~(USISRL ^ switchStatus); // compare current switch positions with previous, // difference will result in 1, invert, 0 means switch not ready switchStatus = USISRL; // save current switch positions, use them when ready flag is 1, // in next round this will be read as previous if(switchReady & 0xFF) { // when all 8 switches are ready Here's how it works (first value is switchReady, second switchStatus (or position,) switches are off) 11111111 00000000 Now we flip one switch 00000001 11111110 (0 means switch is not ready, bouncing, switchReady & 0xFF is false) 00000001 Then on the next round 11111111 (1 means switch is ready, switchReady & 0xFF is true) 00000001 Now we switch it off 00000000 11111110 00000000 And next 11111111 00000000 Because we do not know when the switch was pressed. If we used interrupts and the switch triggered it, we could simply wait 20ms for it to settle and then verify or assume all is good. In our case, we have 8 switches and all could have been switched at different times. For example switch 0 was pressed at t, switch 1 at t+18ms, then we latched at t+19ms, switch 0 was OK by that time but switch 1 was bouncing and we latched off instead on. For this project it doesn't really matter because we are only displaying the value, but if it was doing something else, it could matter. I figured I will include that as an example of how I am handling de-bouncing. Also, I am testing if all switches are ready, but they can be tested individually, something you cannot easily do with interrupt/WTD method.
  13. That will work too. De-bouncing. We check switches every 20ms and if there is a change in switch's position, most likely switch was pushed/released and it's bouncing. We mark it ready when the current position is the same as the last one.
  14. Yep, not active at the moment, too many responsibilities
  15. No, long time ago, when I was young and pretty, I spent a lot of time working with 74s. There were no PICs, MSP430s, etc., just things like Z80, 8255, and lots of 74s. Good old days. Now I work as Java programmer for a big bad bank.
  16. Good catch Mike. Those resistors should be pulling low and the switches should be active high. As it is on the schematic, to be inactive all switches have to be closed drawing unnecessary current. To fix it, resistors should be connected to GND and switches to Vcc. 73 Rob K1WAW
  17. OK, so this will be the last one, the simplest one, one chip, 8 switches 4 pins, 16 switches 5 pins, 24 switches 6 pins, etc., just add D lines. A0-A2 are connected to output ports, D0-Dx are connected to inputs.
  18. This can be fixed using diodes. In fact, even if you decide to use solution like 74hc138/151/393, you will still need diodes because 138's outputs are not open collector. 3 chips, 8 diodes, 8 resistors, 64 switches this one uses 3 74hc03 open collector NAND gates, shown only 5, but you get the idea last but not least, 64 switches with shift register and 6 pins, 3 to address 138, clk, latch, and serial in. 2 chips only.
  19. I think using sprintf for something like this is an overkill. Lots of other functions are included. You are looking at 1.3k overhead.
  20. I guess it all depends on the manufacturer. I think the problem is that the lower 4017 will always saturate one of the transistors no matter if the collector is at Vcc or not. The current will flow through 2k2, T1, 2k2, and then the final transistor. Another problem I see, if you push two switches at the same time, you will short 2 outputs of the top 4017 when one is high and other low. How about something like this: Other suggestions: 1. instead of transistors, use 10 open collector AND or NAND gates, 3 chips. 2. if you can live with 80 switches, how about multiplexer, like 74hc151 and a binary counter instead of lower 4017. 3. if 64 switches are enough, demultiplexer (74hc138), multiplexer and one 8 stage or two 4 stage binary counters.
  21. Can we increase the number of recent topics to 10?
  22. Macros will be replaced at compile time so you will not be wasting cpu cycles. Looks like someone has already created that header file, thanks for the link.
  23. You are using HCT with 3.3V. Did you try 5V?
  24. You can define a function that will convert your "binary" input (long) and return a value. BIN(00100010) Or you can waste some time and create include file with 256 binary numbers as definitions #define B00001111 0x0F #define B00010000 0x10 etc.
×
×
  • Create New...