On Tue, Apr 3, 2018 at 7:44 PM, Mike Naberezny <mike@naberezny.com> wrote: > > I used an AVR pin change interrupt to detect an edge on a past project. The > code was in assembly. The AVR has a large number of working registers so I > reserved one of them for the pin change interrupt service routine. The very > first instruction of the ISR, before preserving registers or anything else, > was to read the port into that dedicated register. This was to capture the > state of the pin as close in time as possible to when the edge occurred. > The ISR would then compare the value to detect the edge and either continue > or bail out. > > Source code: > https://github.com/mnaberez/vwradio/blob/b06c3a95f9b345dc4330cc3a8751b3f6244829ba/avr_volume/firmware/m62419fp_spi.asm#L50-L61 > > This is only an approximation of edge detection. Several processor cycles > will occur between the edge and that first instruction of the ISR capturing > the port value. The pin may change state again during that time. In my > project, the signal I was sampling was slow enough that this was acceptable. > > Regards, > Mike Nice clever approach! I'm familiar with the syntax but I never handled these microcontrollers with only assembly. So I'll definitely go along the C route even if I hate soldering bodge wires. On Tue, Apr 3, 2018 at 8:49 PM, Jim Brain <brain@jbrain.com> wrote: > I would recommend not starting/stopping. Just set up a free running > counter, with the accuracy you need, and then do: > > > ISR() { //counter 0 compare match, runs at 10uS > if(ctr < 255) > ctr++; > } > I didn't want to use interrupts for measuring time thinking they might interfere with external interrupts but I see there are separate bits for each interrupt. So timer interrupts don't inhibit external interrupts. Instead of 10uS I used 50uS. I wanted to be more verbose about the status of transfer so I created two separate state machines, one for bit transfer and another for byte transfers. Possibly there are redundant parts in the code but I tested in the Atmel Studio and it seems to be working. Here is the Attiny85 code : https://pastebin.com/7YWL0e9G I also wrote the kernal selector program. https://pastebin.com/a17v1sJB Gave it a try and guess what :) It didn't work. I grabbed my logic analyzer and sampled /OE line while kernal selector is running (it disables interrupts and only accesses kernal to clear the screen upon launching). There seems to be lots of accesses even if I think I did cut access to kernal. Back to the starting point :) Regards, NejatReceived on 2018-04-09 02:00:02
Archive generated by hypermail 2.2.0.