here is the basic idea, i want to be able to get the time in "ms" that the port is on and save it
#chip 16F688, 8 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
InitTimer1 Osc, PS1_1
Dir portc.1 in
main:
if portc.1 on then startTimer 1
if portc.1 off then
stopTimer 1
epwrite 1, timer1
cleartimer 1
end if
goto main
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here are a few of my observations, based on a quick scan of the code:
1) With an 8MHz clock and a 1:1 prescale value, the timer will roll over after just 30msec. Is that long enough?
2) The nesting of your IF statements isn't obvious, as there's a missing END IF
3) Beware of how often you write to EEPROM, as it wears out after some number of writes (read the spec)
4) There will be a time delay for every EEPROM write (a couple of msec??) that will make the timing inaccurate and variable.
5) If your program has to do anything else except poll the PORTC.1 input to determine its state, the whole timing scheme will be blown out of the water.
A better way to do this might to be to use a PORTB input, set it up so that an interrupt is generated whenever the input changes, read a continuously running TIMER1 on each interrupt, and calculate the difference in timer values between interrupts. This will ensure that you always get an accurate, reproduceable timing no matter what else your program has to do.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is the basic idea, i want to be able to get the time in "ms" that the port is on and save it
#chip 16F688, 8 'mhz
#config OSC=INTOSC, MCLRE=off, WDT=off
InitTimer1 Osc, PS1_1
Dir portc.1 in
main:
if portc.1 on then startTimer 1
if portc.1 off then
stopTimer 1
epwrite 1, timer1
cleartimer 1
end if
goto main
Here are a few of my observations, based on a quick scan of the code:
1) With an 8MHz clock and a 1:1 prescale value, the timer will roll over after just 30msec. Is that long enough?
2) The nesting of your IF statements isn't obvious, as there's a missing END IF
3) Beware of how often you write to EEPROM, as it wears out after some number of writes (read the spec)
4) There will be a time delay for every EEPROM write (a couple of msec??) that will make the timing inaccurate and variable.
5) If your program has to do anything else except poll the PORTC.1 input to determine its state, the whole timing scheme will be blown out of the water.
A better way to do this might to be to use a PORTB input, set it up so that an interrupt is generated whenever the input changes, read a continuously running TIMER1 on each interrupt, and calculate the difference in timer values between interrupts. This will ensure that you always get an accurate, reproduceable timing no matter what else your program has to do.
Can you give an example of code for the "better way" you are talking about if poss