Ok. After several hours of searching. I gotta ask for some help. I’m a biologist, not an electronics engineer or a programmer, so I have trouble making sense of datasheets, defining registers, writing assembly code, and all of that other stuff that PBP usually takes care of. Despite my caveman ineptitude I have managed to put together several devices that have been useful in my field work—mainly things like data-loggers.
I’m now working on a very simple data logging device that stores a time stamp whenever an external sensor is triggered. Basically the PIC could be asleep most of the time and wake up only to write a timestamp from an external real-time clock to an eeprom memory IC. Right now the external trigger is just a switch, and I am monitoring it by polling a pin with IF statements . However, the time during which the switch will remain high (triggered) could be very short, so I have to poll the switch every 10ms to make sure I don’t miss something (and the PIC does not get to sleep).
This application obviously calls for an interrupt, and I think I have found the resources I need to pull this off when using a simple on/off digital input. But, I would like to replace the switch with a flex sensor to eliminate any moving parts and corroding contacts (the device will have to live outdoors). This brings me to my first question:
The flex sensor gives an analog input, and although I believe it is possible for analog inputs to trigger interrupts, I can’t locate any resources to help me make it work, to say nothing of adjusting the sensitivity (i.e. the magnitude of the change in voltage that will cause an interrupt). Does anybody know of code examples or explanations that touch on interrupts triggered by analog inputs through the analog/digital converter (or comparators)?
My second question has to do with using “ON INTERRUPT” vs assembly language. I think either would work (my timestamps do not have to be exact, so latency should not be an issue), I would like to use ON INTERRUPT because that’s where I am on the learning curve, but I don’t want to miss any events that should trigger the interrupt. When you use ON INTERRUPT, does the PIC constantly monitor for an interrupt, or does it only poll the interrupt port at the end of each command? For example if you have a 1000ms pause and an event occurs 100 ms into the pause but ceases 900 ms into the pause, is the event missed? If so, suppose I will need an asm interrupt or very short pause periods.
I am using a PIC16F688 for now, but could switch to something else if need be. My instincts tell me that the solution to this problem will involve PIR1, the PERIPHERAL INTERRUPT REQUEST REGISTER 1:
bit 7 EEIF: EEPROM Write Operation Interrupt Flag bit
1 = The write operation completed (must be cleared in software)
0 = The write operation has not completed or has not been started
bit 6 ADIF: A/D Interrupt Flag bit
1 = A/D conversion complete
0 = A/D conversion has not completed or has not been started
bit 5 RCIF: USART Receive Interrupt Flag bit
1 = The USART receive buffer is full
0 = The USART receive buffer is empty
bit 4 C2IF: Comparator 2 Interrupt Flag bit
1 = Comparator 2 output has changed (must be cleared in software)
0 = Comparator 2 output has not changed
bit 3 C1IF: Comparator 1 Interrupt Flag bit
1 = Comparator 1 output has changed (must be cleared in software)
0 = Comparator 1 output has not changed
bit 2 OSFIF: Oscillator Fail Interrupt Flag bit
1 = System oscillator failed, clock input has changed to INTOSC (must be cleared in software)
0 = System clock operating
bit 1 TXIF: USART Transmit Interrupt Flag bit
1 = The USART transmit buffer is empty
0 = The USART transmit buffer is full
bit 0 TMR1IF: Timer1 Overflow Interrupt Flag bit
1 = Timer1 register overflowed (must be cleared in software)
0 = Timer1 has not overflowed
Bookmarks