Quantcast
Channel: MCS Electronics Forum
Viewing all articles
Browse latest Browse all 21194

BASCOM-AVR : Problem with bitwise operation inside sub - Please help. : REPLY

$
0
0
[quote:7bb95ac6eb="JC"]Its been a while since I wrote some code, so perhaps I'm missing something, but: 1 MHz clock, divided by a Pre-Scaler 0f 1, gives a 1 MHz clock into the Timer/Counter. Setting the compare value to 46874 means that the T/C will have 46875 counts per period. The one extra count is for roll-over from the 46874 value back to 0. 1 MHz / 46875 gives 21.3 interrupts per second. Your comment indicates an interrupt once every three seconds. Next suggestion: If you want accurate timing one uses the T/C. If you want to toggle a port pin on a given time interval then don't poll the bit (flag) in a software loop. This adds an unknown delay. Just toggle the port pin in the ISR itself, then return. Lastly: Should Clear Timer = 1 be Clear_Timer = 1 I don't have a board out to test this at the moment. JC[/quote:7bb95ac6eb] Thanks JC, I should have removed the comment about the interrupt happening every 3 seconds. Originally I had the prescaler set to 64, which did give an interrupt every 3 seconds(approximately). I changed the prescaler to 1 so that I could observe the anomaly on an oscilloscope without having to wait so long. Interesting about "Clear Timer=1" and "Clear_Timer=1", the compiler accepts both statements. There is no difference to how it operates with either statement.

Viewing all articles
Browse latest Browse all 21194

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>