AC Electric Field Aliasing Dynamic Waveforms in 68HC11 - Page 1
Forum section: electronics / general

author: planc
author_rank: Regular Contributor
timestamp: January 24, 2023, 10:29:25 am
content: In the late 1990s. I bought a simple EEG that uses the Motorolla 68HC11 the reads the ADC signals and output them to serial port.If you don't know how exactly EEG works. It simply gets inputs at microvolt using active and reference electrodes (matching the -In and +In differential inputs of typical op amps and instrumental amps plus ground), and then amplifies it 20,000 times (Note: modern EEG doesn't amplify it so much because it uses 24 bit ADC). But I lost interests in it as soon as I got the unit (never even tried running it), so I put it in the attic. And 23 years later last year October. I took it from the attic and tried to run it. I was surprised the 1.44Mbyte diskette still worked after I was able to find a USB disc drive. Unfortunately, I tried to run the latest PC software and it bricked the firmware by overwriting memory B620 and other locations such that I couldn't run it anymore.So I spent months studying the HC11 after I googled about it and learnt how to access the EEPROM memory via serial terminal software. Last December after being familiar with the HC11 assembly language. I was able to figure out the deleted firmware codes and able to run it fully (including 2 channels ADC and simultaneous display of them that uses character synchronization that I couldn't figure out how to do without the firmware)..(edit. the above is illustration of raw EEG at top and the filtered alpha, beta, etc. wave. In my unit, I was seeing the raw waveform with AC electric field distortions. This was when there are no electrodes connected)In my tasks to understand the HC11. I tried to run simple separate assembly programs at the RAM (not using the firmware of the initially bricked EEPROM) that reads the ADC and displays the hex characters at the serial port. For the first few weeks after I figured out how to write them. I saw waveforms like this:The waveforms can change depending on the delays between ADC reading (note the delays between ADC read and serial port write but between the ADC reading).For 2 weeks I couldn't understand why it displayed like that. Until one night last November I removed the ac power cord plug, then the waveforms got back to more normsl waveforms immediately (see photo below).Later I found out it is the electric field in the extension wire outlets in the table that could distort the waveforms. In the following picture, the actual waveform noise got removed halfway after I unplugged the empty extension cord.. It is not direct AC line interference because nothing was plugged into it and it the electric fields.After learning some HC11 assembly language. I wrote the following original program that can decrement the delays between the ADC read from FFF down to 1. That is. initially FFF to 1. Then FFE to 1, then FFD to 1, until it reach 002 to 1. In other words it changed the delays between the time it reads the ADC (Note the time between ADC read and serial port display is the same in all loops.Code:REGBASE EQU $1000ADCTL2 EQU $30ADR1 EQU $1031OPTION EQU $1039SPCR EQU $1028BAUD EQU $102BSCCR1 EQU $102CSCCR2 EQU $102DSCSR EQU $102ESCDR EQU $102FORG $0110STARTLDAA#%10011000;enable ADCSTAAOPTIONLDAA#%00110000 ; 00110000 = 9600 BAUDSTAABAUD ; 00110011 = 1200 BAUDCLRSCCR1LDAA#$0CSTAASCCR2 ;RECEIVER & TRANS. ENABLEDclrSPCRRESETTING ldy #$fff ; fff is the maximum time that will decrement by 1 between ADC readsty $0005 ; $0005 is the address where the decremental fff is storedLOOPLDX #REGBASE ; enable ADCLDAA #%00000010STAA ADCTL2,Xldy $0005 ; delay before ADC read & output (will decrement from a decreasing initial fff to 1)next_delay deycpy #1bne next_delayldaa ADR1 ; read ADC value and send to serial portread_again ldab$102e ; read first Statusbitb #80beq read_againstaaSCDR ; save in TX Registerldx $0005 ; this will decrement fff by 1 then jump to LOOP before resetting if value becomes 1dex ;stx $0005ldd $0005cmpd #1beq RESETTINGBRA LOOPIt outputs waveforms 00 to FF at the serial port, and with decreasing time between ADC read, that looks like this (youtube video). Note the waveforms below the top raw are the frequency filters (bottom is around 60 Hertz). The box below it the Phase-Space or chaos/order output.A few days ago. I suddenly thought that if it was aliasing the changed the waveforms! If you will see the video. The delay between each ADC reading got quicker and quicker until it resets back to long ADC sampling read. In the following picture, I plugged the extension above and the electric field changed the waveforms immediately.In the bottom photo above the delays between ADC read is around halfway or 777 to 1 (remember the initial delay count is FFF to 1 for 1st ADC read, then FFE to 1 delay for 2nd ADC read, and so on until it reaches 001 to 1 or no delay between ADC rea)d. However, notice the waveform reverses halfway. I know how aliasing creates waveform that is not there at the original due to undersampling. But how could you explain the waveform reversing at the middle? In the following the delay between ADC read reaches 001 to 1 so it resets back to FFF to 1.My questions:1. What kind of AC electric field aliasing can reverse the waveforms halfway??2. For the 68HC11. How long would it count from FFF to 1?3. You can see the waveforms output at the serial port terminal. What kind of software can you use to count how many samples per second or Bits per second or Baud it is actually sending the characters? I used the 9600 Baud because that's how Buffalo resident monitor program must be using.Thank you.

author: Whales
author_rank: Super Contributor
timestamp: January 24, 2023, 11:42:47 am
content: QuoteTry redirecting the serial port to a text file. Run it for X time (eg 60 seconds) and then check the file size.I'm completely lost in parts of your post, sorry. Eg:QuoteIn your images and video you have a dimension of time (left-right), a dimension of amplitude (lines going up/down), a dimension of row (which coloured line) and a dimension in the form of a text number rendered to the right of each row. This is four dimensions, only the first two of which I can clearly understand.I don't understand what the 3 axes (x, y, which plot) on the circular plots in the bottom are either:QuoteI couldn't find a narrow definition of those words on the web, maybe I'm missing something?If you're experiencing weird sampling related artefacts then these are the questions that might be worth answering:(1) What is the analog filter in front of the ADC? I presume it will have both highpass (to get rid of DC) and lowpass (anti-aliasing and anti-noise). Normally you would design the filter to get rid of unwanted high frequencies, but of course that's the fun that you are exploring.(2) Is the sample rate consistent? ie are you tied to a hardware timer or just hoping/planning for code execution to take the same amount of time every loop? Might be worth toggling a pin every time you sample the ADC, then you can monitor this pin on an oscilloscope and see if the period is stable or not.Uneven sample rates combined with code that can take different amounts of time to execute can create weird oscillations of its own. Eg if you read a big number you might then spend more time writing more digits over the serial port, which might cause some sort of positive feedback that keeps the big reading oscillations going.(3) Make sure you don't have two layers of aliasing! Eg a freerunning ADC that samples a X hz signal at sample rate Y, but then a main loop that reads the ADC results from a register at sample rate Z. X > Y > Z. You now have even more chaos

author: planc
author_rank: Regular Contributor
timestamp: January 24, 2023, 12:57:44 pm
content: (the color lines below the raw is just the alpha, beta, gamma etc. wave and user defined (60 Hz I made))I have a 2nd unit current modern EEG. I just want to understand the time changing aliasing of the old EEG unit above (which no modern EEG uses anymore). I know it is very inadequate, I just want to understand the noise part and not remove it (I don't use that old EEG in any application at all). The above is the analog part. Vo is connected to the HC11 ADC input.About the ADC. In modern MCU, you use compare channels to maybe delay time between each ADC register read. Some old MCU use real time interrupt. In my case example. I just use timer. For example the loop FFF will count to 1 between reading of the ADC registers or contents. However in the program I shared above. I made the delay decrement in each loop. So the aliasing has changing waveforms (timer counting down). I thought most understand the HC11 and can easily tell from the code what it is doing?My question is I was expecting the waveforms to get wider and wider as the delay reaches lower count, then reset. But why does it get wide midway then narrows again. I want to understand the interactions of time changing aliasing.About Phase-Space. This is written in the manual:"Phase-SpaceThis is a 2-dimensional display using "rate of change" in place of the time axis, common in "chaos" analysis. The vertical axis is exactly the same as in the EEG waveform display, e.g. "amplitude," while the horizonal axis is the "first derivative," or "rate of change" of the EEG signal. This display is interesting because very smooth, coherent waveforms will appear as rounded, open circles, while fast or irregular activity will produce flatter shapes, with more internal detail. One use is for training for general EEG amplitude reduction, which will be shown as the "object" becomes flatter, and generally smaller."Oh. I should have omitted that Phase-space thing in the video because it is not related to my question. Other words for Phase-space is chaos mathematical plothttps://www.cfm.brown.edu/people/dobrush/am34/Mathematica/ch3/chaos.html

author: planc
author_rank: Regular Contributor
timestamp: January 24, 2023, 01:55:58 pm
content: If you don't understand my initial message (don't miss the reply above to another's question). Please just refer to the following simple new youtube video where I use the original firmware and not my modified changing sampling.In the video. I turned it on but without the extension cord plugged in, meaning initially there was no interference from ac line electric field. Then halfway in the short 19 sec video. I tried to plug the empty extension cord. You can see the particular waveforms to the end like the above. My question is. With 60 HZ AC electric field, what is the origin of that particular waveform shapes (and not other shapes you can see in the initial message video where I alter the sampling to vary)?I showed the filters waveforms below the raw so you can see the aliased shape doesn't have the frequency of 60 Hz.By the way, before I plugged the extension, you can see the waveforms being distorted. That's because it can also detect my body electric field distortions in the electrostatic component even a meter away. But that's not my question because my focus is the AC field shape and how to determine the shapes.

author: ozcar
author_rank: Frequent Contributor
timestamp: January 24, 2023, 07:32:11 pm
content: Quote from: planc on January 24, 2023, 10:29:25 amSo, you are executing this:Code:ldy $0005 ; delay before ADC read & output (will decrement from a decreasing initial fff to 1)next_delay deycpy #1bne next_delayYou would have to look up how many cycles each of those instructions in the loop takes (from my quick look, 4+5+3 = 12 in total) and then multiply that by the cycle time to get the time to do those three instructions once, then multiply by the number of times the loop is repeated. As far as I can see you have not mentioned what rate the processor is clocked at to translate that to actual elapsed time.Note, if you really could enter that code with delay value of 1 in location $0005 (as the comment could be taken to mean), it would loop some 65 thousand times before proceeding.BTW, this looks wrong:Code:read_again ldab$102e ; read first Statusbitb #80beq read_againstaaSCDR ; save in TX RegisterThat is not correctly testing for "transmit data register empty" due to using incorrect immediate operand #80 (decimal 80). It should be #$80 (hexadecimal 80).It has been a long time since I had a HC11 to tinker with...

author: planc
author_rank: Regular Contributor
timestamp: January 24, 2023, 09:23:33 pm
content: Quote from: ozcar on January 24, 2023, 07:32:11 pmThe crystal frequency is 8 Mhz. The firmware uses real time interrupt and time of 8.19ms. When I adjusted it to 4.10ms. There is Communication Overflow in the buffer. Know how to overcome it? E clock is 2 Mhz. So cycle time is? Maybe you have online app that can compute the total time?The program I shared was exactly ran as it is. I just adjusted #80 to #$80 (Yeah, it took me many days back in October to figure out the difference). But the output is the same. The following is the terminal output after I ran the command g 0110 (after assembling the txt with edited #$80 into .s19 file). Then load the pc software to look at the waveforms (I shared in the video)So anyone got ideas what created all those waveforms shapes The contents of $0005 is initially FFF, after every loop where it reads the ADC register, it decreases to FFE, FFD down to 001 (see the dex command).I'm thinking what could create the particular shape is the frequency of the sampling plus 60 Hz AC electric interference, right? Please prove it by drawing the sample frequency and 60 Hz and how they could come up with the particular waveforms depending on the sampling frequency. Thanks.

author: planc
author_rank: Regular Contributor
timestamp: January 24, 2023, 11:27:34 pm
content: The following is very clear.Last October when I was just learning how to read ADC and display them at serial (to fix the bricked firmware). I always did fixed time delays between reading of the ADC registers. I was figuring out the best delays so it would fit the pc software. If there were no delays, the output would be just flat like the following: (It is only last December that I wrote the program with time varying delays just to display all the waveforms). But let's focus on fixed time delay now to compute the cycle time.So delays are necessary. In the following program I use fixed delay of 800 to 1 for the first waveforms (and A00 to 1 for the second waveforms)Code:REGBASE EQU $1000ADCTL2 EQU $30ADR1 EQU $1031OPTION EQU $1039SPCR EQU $1028BAUD EQU $102BSCCR1 EQU $102CSCCR2 EQU $102DSCSR EQU $102ESCDR EQU $102FORG $0110STARTLDAA#%10011000;enable ADCSTAAOPTIONLDAA#%00110000 ; 00110000 = 9600 BAUDSTAABAUD ; 00110011 = 1200 BAUDCLRSCCR1LDAA#$0CSTAASCCR2 ;RECEIVER & TRANS. ENABLEDclrSPCRLOOPLDX #REGBASE ; enable ADCLDAA #%00000010STAA ADCTL2,XLOOP2BRCLR ADCTL2,X #$80 LOOP2ldy #$800 ; delays between ADC register readingnext_delay deycpy #1bne next_delayldaa ADR1 ; read ADC value and send to serial portread_again ldab$102e ; read first Statusbitb #$80beq read_againstaaSCDR ; save in TX RegisterBRA LOOPThe following is the output (without AC interference)When I plugged the blank extension coil, the 60 Hz AC electric field produces the following interference. Just focus on the first line because the others with numbers are just the filters (original for alpha, beta, etc. but it depends on the raw signal so can change).When I changed the fixed delay to A00 to 1 (and 60 Hz AC on too). I got the following waveform.It is really Aliasing, isn't it? I was just thinking it was Aliasing just 2 days ago. I didn't know what they were last December and I almost forgot about them. The HC11 may be the last one I'll use because modern MCU like MSP430 are just so hard.With the very simple program above. What is the frequency of the last picture with fixed delay of A00 to 1? How did the waveform above come out when 60 Hz AC is added? Again the HC11E9 clock is 8 Mhz with E-clock of 2 Mhz as I mentioned in last messaage.That's all I wanna know.By the way. The AC noise waveforms only come out when nothing was connected to the electrode inputs of the amplifier. When electrodes were connected to the head. The noises didn't show up because then the signal in the electrodes were direct to your skin so stronger signal entering them versus the case with no electrodes and the amplifier just picking up the effect of changing field of electric potential in the room, and thus also changing electrostatic component of total electric field.Thanks.

author: planc
author_rank: Regular Contributor
timestamp: January 25, 2023, 02:25:34 am
content: Here is another info in addition to the above that can shed more light and another question.The RS-232 serial display plots hex values between 0 to 255 (0 to FF from the 8 bit ADC). In the following I wrote program that would plot values 0 to 255 and it displays it with 0 at the top most peak and 255 at the bottom peak.Code:REGBASE EQU $1000SCS EQU $2EADCTL EQU $1030ADR1 EQU$1034OPTION EQU $1039SPCR EQU$1028BAUD EQU$102BSCCR1 EQU$102CSCCR2 EQU$102DSCSR EQU$102ESCDR EQU$102FORG $0110STARTLDAA#$1032; 3 & 4DEX; 5STAB $0424; 6 7 8LDAA#$1032LDAA#%10011010STAAOPTIONLDAA#%00110000 ; 00110000 = 9600 BAUDSTAABAUD ; 00110011 = 1200 BAUDCLRSCCR1LDAA#$0CSTAASCCR2 ;RECEIVER & TRANS. ENABLEDclrSPCRLDX #REGBASELOOPldaa #255; delay timenext_delay decaldab SCSRstaa SCDRBUFFSBRCLR SCS,X #$80 BUFFScmpa #0bne next_delaybra LOOPMy question. Does serial display have any sampling frequency too? How does the RS-232 pc serial display work? Can it interact with the 60 Hertz AC aliasing waveforms?What pc app can I download that can output 0 and FF values sent from the serial port similar to the above? In the default EEG app, I can't change the display parameter like sampling or seconds, etc. (Pls don't suggest complex serial display software that can be embedded at programs because I don't know how to use C language or others. In my 3 months of nightly study of the HC11 assembly language. I only wrote 2 programs besides reading ADC and displaying it and that's it.)

author: ozcar
author_rank: Frequent Contributor
timestamp: January 25, 2023, 03:56:26 am
content: With an 8MHz crystal, the bus frequency ("E-clock") is 2MHz, so 1 cycle is 500ns. So, by my reckoning the dey/cpy/bne takes 6μs. So for delay count of n (and n>1) you would get a delay of (n-1)*6μs. But check those cycle counts in the reference manual for yourself.Quote from: planc on January 24, 2023, 11:27:34 pmAs it stands, for very low delay counts (n< 6) it looks like you would try to read the ADC result before the conversion is complete.Quote from: planc on January 25, 2023, 02:25:34 amOf course, there is a maximum rate you can get around the loop which will be largely dependent on the time to transmit the result (around 1ms at 9600 baud). But I'm not sure if that is what you are asking there.

author: planc
author_rank: Regular Contributor
timestamp: January 25, 2023, 11:56:41 am
content: Quote from: ozcar on January 25, 2023, 03:56:26 amIt takes 4 seconds for the waveforms to to fill the screen and there is a time in seconds on top too showing 4 secs each screen. The display sampling used is 128 samples per second, with baud rate of 9600. If the screen display becomes twice at 256 samples per second. The output would take twice longer? That's why I need a third party serial display that can make you adjust the samples per second and see if the waveform shapes would vary. So the only characteristic of a serial wave pc outside software is the sampling per second?Or are the waveforms shapes dependent on the 60 Hz electric field and the program loop delay for each sampling only? I still can't find the relationship of the waves. For example, the waveform shape at loop delay between ADC display of BFF TO 1 AND 1EFF TO 1 is very similar. It's as if the wave shape is repeating after certain loop. What kind of aliasing have you seen that can do that? Aliasing with harmonics? Or is it even aliasing?

author: ozcar
author_rank: Frequent Contributor
timestamp: January 26, 2023, 11:17:05 am
content: The code as you posted originally changes the delay count, and hence the sampling rate between every single sample taken. I'm not going to try to guess what that will do, but I would not be surprised if you got a hard-to-explain result. As well, and as already mentioned, a very low delay count could cause you to read the ADC result register before the conversion is complete. In any event, you can't get it to sample faster than about 1kHz due to the serial transmit time.Some random thoughts:You might be able to increase the serial transmission baud rate. For an 8Mhz crystal, the maximum rate is 125k (from table 9-3 in the Reference Manual). Some programs and/or serial ports might not allow you to use a "non-standard" baud rate, but I did a test here and Tera Term was quite happy to work at 125k baud using a CH340G USB-serial converter.Also, if you had enough ram on the HC11, you could just stash some number of ADC readings, then stop sampling and transmit the results at your leisure.You could get to see the raw data, without lifting a finger to write your own code too. Tera Term allows you to capture the received data to a log file. You could look at that with a hex editor to check the values received. Then you can get Audacity to show you what it looks like and maybe even give you a frequency analysis provided you tell it the sample rate (File/Import/Raw Data..., Encoding: Unsigned 8-bit PCM. 1 channel).