NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Strobe Scope with Phase adjustment
June 14, 2020 by scootergarrett |
I'm trying to make a strobe scope that takes an input signal from some sensor (hall effect, laser, doesn't really matter at this point) and flashes a light at a user selected phase. For the rest of this example lets say 180deg. Said another way, an incoming 500Hz signal (2ms period) the program would detect the incoming signal pulse and flash 1ms later I was using the delay functions, but was having issues with high phase angles (300deg and up), I think caused by interrupts overflow, also it seems like the wrong way. Now I'm trying to use the TCNT1 counter to both measure the time between input pulses and control then the output is turned on and off. I think there is a way so when the counter TCNT1 hits OCR1A and OCR1B it will change OC1A (PB1) state on and off respectively. I have some code that just toggles the state of PB1 when it hist OCR1A.
Is anyone here? and really good with the timer settings? |
---|---|
July 03, 2020 by scootergarrett |
I got something working well. I have boiled down my code (and this solution) to just the strobe timing problem. The code I've been using is more complex then needed to enplane the the tricky/ clever part. I wanted a light to pulse very quickly based on a sensor detecting cyclical motion; similar to a timing light flashing with it detects a spark. High intensity flash synced with a rotation object will make it appear to hold still. In my case I wanted the ability to flash not when the sensor detects a passing mark but a given phase later. This way I could slowly adjust the phase angle giving the illusion of slow motion. First the code:
I used the 16bit timer and a lot of the features the MCU will do on its own. I was running into issues at high phase angles (close to 360deg) when the interrupt would happen before the light had turned off, my solution was to blink every other time the sensor sent a pulse. Note I re boot loaded making PD7 The reprogram pin, because PB0 functionality with the timer .I marked up the to show the 'flow' of the program. Also a with actions 1-4 doing the following 1) Puts TCNT1 into ICR1, Interrupts (TIMER1_CAPT_vect) Resets TCNT1, Calculates the time B and C based on ICR1, Sets OCR1A to point B, Sets to turn on OC1A on match , Clears EveryOther. 2) Sets OCR1A, Interrupts (TIMER1_COMPA_vect): Sets OCR1A to point C (saved as A2), Sets to turn off OC1A on match. 3) Clears OCR1A. 4) Puts TCNT1 into ICR1, Interrupts (TIMER1_CAPT_vect) just sets EveryOther. |
July 03, 2020 by scootergarrett |
Sorry picture links didn't work reposing I used the 16bit timer and a lot of the features the MCU will do on its own. I was running into issues at high phase angles (close to 360deg) when the interrupt would happen before the light had turned off, my solution was to blink every other time the sensor sent a pulse. Circuit Diagram Note I re boot loaded making PD7 The reprogram pin, because PB0 functionality with the timer .I marked up the block diagram to show the 'flow' of the program. Also a Timing diagram with actions 1-4 doing the following |
July 03, 2020 by scootergarrett |
The results are hard to show. I have a set up with a fan spinning with a magnet attached that a hall effect sensors is picking up. I'm using a 10W LED and turning off all the lights. the fan appears to hold still but when I record it the video is flashy, shutter speed issues. Here are some scope pictures, (side note the analog discovery 2 is amazing) input signal-blue ouput signal-yellow Now I'm done |
July 13, 2020 by bluestang |
I am here, but sorry i am no good with Timers. |
August 27, 2020 by sask55 |
Hi Interesting approach. I assume there is some reason you have decided to use a phase angle approach in this project. It seams this approach is more suited to giving the appearance of stopping the motion at a selected angular rotation position then giving the illusion of slow motion. i.e if the rotation position of the trigger timing is at 0 degrees (12 o'clock) but you wish give the illusion that the trigger position is at 90 degrees (3 o'clock) then this setup is ideal. You can select any angular position you like to give the illusion of no movement i.e. stopped at that position. However, if your goal is to give the illusion of slow motion in ether direction then is seams to me what you want is a flashing strobe that is out of sink with the input signal. Instead of varying the phase angle the system would simple increase (appears to move backwards) or decrease (appease to move forwards) the frequency of the strobe by relatively small amounts. The system could measure the frequency of the input signals. The output could be set to flash at any factor of that frequency to give the illusion of a stopped rotation. This assumes that there is limited other sources of light and is most effective at strobe frequencies above ~30 HZ. The frequency adjustment can easily be calculated and applied to give the illusion of any speed of slow motion rotation that is selected. |
August 28, 2020 by scootergarrett |
Once I got it working at a set phase angel I just made the phase angle variable slowly increase 0-360 |
Please log in to post a reply.
Did you know that interrupts can be used to trigger pieces of code when events happen? Learn more...
|