Ttelmah
Joined: 11 Mar 2010 Posts: 19481
|
|
Posted: Thu Jun 28, 2012 1:32 am |
|
|
Get rid of the code disabling and enabling interrupts in INT_RDA.
The _hardware_ handles this.
You have an absolute 'killer' in there - a search here will find more, but you must _never_ repeat _never_ 'enable_interrupts(GLOBAL)' in an interrupt handler. Doing so, _will_ result in the code/chip giving unexpected results/crashing.
Second killer though is having delay_ms(1) in the timer interrupt.
Simple rule of thumb for interrupts, only to be broken if you _know_ exactly 'why', and what you are doing, is that each interrupt handler, should _just_ do the job the interrupt signifies, _and get out ASAP_. Delays in interrupts _will_ cause problems. You are stuck inside the timer interrupt for over 8mSec. At 9600bps, this means that 6 serial characters can have been lost.
Final thing, though it 'breaks' the comment about not using delays, is that you will almost certainly need:
Code: |
void Latch_data()
{
output_low(LATCH);
delay_cycles(1);
output_high(LATCH);
}
|
'delay_cycles(1)', just inserts a single 'nop' instruction. Performing an output_low, followed immediately by an output_high, is _not_ guaranteed to actually cycle the pin (depending on the loads present). The single machine cycle delay avoids problems with this.
You need to take all your code out of the timer2 interrupt, and just have this set a flag. Perform the SPI writes, and delays in the main code, when this flag is set (and clear it here). This then also moves all the delays outside the interrupts.
As a final thing, get rid of the 64 way loop in the RTCC. This will take an _age_. You are moving data from one memory area to another, so use memcpy. The 64 way loop you currently have, will take about 1800 machine instructions, using memcpy(test,newm,64); will be about 5* faster. Difference is that array accesses are individually slow. Accessing two arrays 'byte at a time', involves about 10 instructions of setup on each side of the copy instruction. memcpy, performs the setup once, and does a block copy. Much better......
Best Wishes |
|