Hi,
I want to use timer0 to bit bang digital outputs (PWM) for controlling LEDs and small servo motors. In theory it should work based on everything I have read on the www.
My questions are:
1) If I am reading/writing EEPROM addresses and the Tmr0 code begins to solve, will this interuption corrupt the eerpom read/write command and/or information?
2) Same question for analog reads and writes, same for other component macros.
Thanks
Ron
timer0 and PWM
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello Ron
In answer to your questions.
1) The EEPROM write routine disables the interrupts before the critical part of the code, This means that your timer interrupt may come slightly late if you are writing to the EEPROM at that particular moment. This will not affect the Timer0 count value and it should interrupt again the next time as if there hadnt been any delay.
2) EEPROM writes are the only totally critical pieces of code. Other code can normally be interrupted without causing adverse affects. The only problem would be if you had taken an ADC sample and then an interrut occurred, Then inside the interrupt you sample a different analogue channel. Obviously this would corrupt the original data so if possible leave things like ADC sample outside of the interrupt routine.
In answer to your questions.
1) The EEPROM write routine disables the interrupts before the critical part of the code, This means that your timer interrupt may come slightly late if you are writing to the EEPROM at that particular moment. This will not affect the Timer0 count value and it should interrupt again the next time as if there hadnt been any delay.
2) EEPROM writes are the only totally critical pieces of code. Other code can normally be interrupted without causing adverse affects. The only problem would be if you had taken an ADC sample and then an interrut occurred, Then inside the interrupt you sample a different analogue channel. Obviously this would corrupt the original data so if possible leave things like ADC sample outside of the interrupt routine.
Last edited by Benj on Thu Jan 10, 2008 10:42 am, edited 1 time in total.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Valued Contributor
- Posts: 548
- Joined: Tue Jun 26, 2007 11:23 am
- Has thanked: 6 times
- Been thanked: 44 times
Hello Ron,
The use of the timer 0 interrupt should not significantly affect any of the other functions if the standard interrupt service rules are observed:
Interrupt services will not affect the timing of the adc, uart, spi etc. as these are hardware controlled.
The use of the timer 0 interrupt should not significantly affect any of the other functions if the standard interrupt service rules are observed:
- Keep the service routines short.
Take care when modifying registers and global variables that may be being used in the main program.
Interrupt services will not affect the timing of the adc, uart, spi etc. as these are hardware controlled.