|
|
View previous topic :: View next topic |
Author |
Message |
jojos
Joined: 30 Apr 2007 Posts: 64
|
Problem of display flashing during sine wave sampling |
Posted: Tue Jan 29, 2008 1:20 am |
|
|
Hello.I wanted your opinion about my problem.I am working on a project in which i am sampling at least 2 sine waves, freq 50Hz,
and i have two 3-digit 7-segment displays to show the voltage of that sine waves the, menu settings etc. To sample these sine waves i need at least
50 SEC for each signal.And here comes my problem.When i get into a2d routine the displays are turning off (as long as the sampling occurs).
It's like a flashing on the displays.
I tryed to sample every 1 or 2 or 3 sec but the problem of course remains. It just change the flashing rate of the displays.
The routine for showing the voltages runs it is inside the main loop where program runs the most.
I use 8 Mhz crystal and th PIC 18F2420. What could i do to avoid this flashing phenomenon? |
|
|
Ttelmah Guest
|
|
Posted: Tue Jan 29, 2008 4:32 am |
|
|
It is difficult from your description, understand what you are really doing. It sounds perhaps as if you are sampling multiple times, and then averaging these readings, over a period?.
It also sounds as if you are multiplexing seven segment displays, performing the multiplexing in a software timed loop?.
If so, then 'of course' the display flickers, when you stop performing the multiplexing to carry out the sampling. I'd guess that the sampling 'time', actually ends up being much more than 50mSec. If (for instance), you are performing a seriesof ADC reads, and adding delays between these to generate 50mSec of time, then performing the arithmetic to average the readings, the 'total', will be way beyond 50mSec. Remember that the ADC sample and reading itself takes time (depending on your selected clocks, probably 40uSec), then the loops, and maths all take time. I'd not be suprised if your 'sample loop', ends up taking more than 100mSec, rather than the 50mSec, you are thinking of. As such, the display stops updating, for quite long enough for the flicker to be visible.
Consider changing your approach totally.
Have a system 'tick' interrupt, at perhaps 500Hz.
In this interrupt, the code can be quite complex, but the timings on each pass, must be 'quick'. So, do two things only:
Have a 'display' state machine, that counts through the output states required. Advance this just one state, change the bit patterns on the display for this state, set the state back to zero, if this is the last display state, and finish.
Have a 'sampling' state machine for the ADC. On the first pass, perform an ADC_READ(ADC_START_ONLY), and return. On the second, perform an ADC_READ(ADC_READ_ONLY), and (if you are averaging), add this result to a 'sum' (stored globally). Set the pass count back to 1. Increment a 'global' counter, and do nothing else.
Now, the main code, does not have to handle displaying the data. All it has to do, is put the 'value' to display into the global variable used by the display routine.
When you need to read the ADC for '50mSec', simply stop the interrupt for a moment. Set the counter to zero, set the sum to zero. Re-enable the interrupt, and simply wait, till the counter reaches 12. Then disable the interrupt, read the 'sum', enable the interrupt, and divide this sum to get the average.
At all times, except for the pauses (which shouldn't exceed a dozen instructions or so), the display _will_ be regularly updating. Even when paused, all that will happen is that the update will be this few instructions _late_, but will still happen. Similarly, the ADC will be taking a reading every 4mSec (every 2 interrupts), and will perform this at these accurate hardware intervals. The pause in the 'main', for arithmetic, after the reading is taken, won't affect the timings.
Best Wishes |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Tue Jan 29, 2008 5:47 am |
|
|
Thank you Ttelmah for your response.I have to admit that i will need some time to understand your solution
but i believe in the end i will .Also here what i am doing exactly.I have 2 sine waves of 50 Hz.During sampling i check for the
max and low of the signal to have the Vp-p voltage for each signal. These voltages then i am taking them out to displays. |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Mon Feb 04, 2008 2:58 am |
|
|
Thanks again Ttelmah and sorry for my late response.Your solution worked. I used a 2 msec interrupt to update the display data and also i am able to sample w my sine wave input for 20 msec each,and get accurate measurements. |
|
|
Ttelmah Guest
|
|
Posted: Mon Feb 04, 2008 3:21 am |
|
|
Glad you got it working. It was quite a complex change to make in the 'approach', so it is good to hear that you got it going.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|