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

BASCOM-AVR : pulse length capture : REPLY

$
0
0
hi Hubert [quote:e5251236f6]If you just want the high or low time in a pulse, then just read the timer in a loop and count system clocks with the other. [/quote:e5251236f6] It's like a reversed freq counter. Timer1 fills up with the systemclock, triggerd by a exteriar blockwave. So the readings are many times more accurate. I would like to reserve Timer0(as counter) to group 4 to 10 of this blocks to one longer, so I have a mean value. This blocks comes from a quadrature encoder (2000 ticks) wich I suspect that the lines are not very equal. (I dont know if my suspicion is justufied). The readings must be absolutely the same for the same wavetrain and with the greatest possible accuracity. I expect 200 ticks/sec; so divided by 4 to 10 is enough to use in PID application on servo DC motor at 10sec pro revolution. But that aside...i'm not there yet. hi MWS [quote:e5251236f6]tcnt1 is never reset, interrupt requests are steadily produced, executed as soon interrupts are globally re-enabled, clock consuming multiplications in the ISR, the ISR is able to interrupt the print and distort the result, a.s.o[/quote:e5251236f6] I will study one by one. I know my code is not correct; at the beginning i was already satisfied to see a series of numbers on the terminal emulator. But what strikes my is the fact that the spreading of the readings is approximatelly allways the same ie 130000 = 2*65536 ??? or +/- 1*Ovf_1. Is this a coincidence? I will readout separately the variables Ovf_0 and I (TCNT1). That will clarify things. hi Adrian i will follow up your recommendations. When i do I=TCNT1 (I=word) then error: source not match the target. I disabled the interrupts because i tayed the atomic read like proposed on pg 93 of pdf manual ATmega16. [code:1:e5251236f6]Even simpler is to let the timer free run, read it on the rising edge, then read it again on the falling edge, and subtract the two values as words. That also gives the possibility to poll several lines, and read the period of each one, using only one timer. You do have to ensure the timer does not roll over more than 65535 counts in one period for this to work. But you can usually avoid this by setting the prescaler properly. [/code:1:e5251236f6] I thougt also to that because the only importent thing is the difference between two readings in the PID loop. But if this is greater then 65535*0.0625 µSec = 4 mSec then i have problems indeed. What happens on start up the dcmotor but this is for later. With PulseIn: the accuracity (10µSec) in not great enough. Maybe i try it out later when i experiment with the PID. Now i will try with the new hits; i keep you up to date in the near future. Ernst

Viewing all articles
Browse latest Browse all 20613

Trending Articles



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