Using ADC value with SKP instruction

Software questions and issues with the FV-1

Moderator: frank

Post Reply
bennettcustomaudio
Posts: 5
Joined: Thu Sep 26, 2019 12:44 pm

Using ADC value with SKP instruction

Post by bennettcustomaudio »

Hi Folks,

I'm developing a code in which I want certain instructions to only execute When there is an input signal present at the ADC, i.e, that part of the code only happens when you're actually playing. My natural inclination was to use the SKP instruction, and if the ADC signal is zero then the instructions will be skipped, like so:

Code: Select all

		LDAX	ADCL		; Load the left channel ADC into the ACC
		SKP	ZRO, skp1	; If value is zero, skip ahead to skp1
		
		; additional instructions..
		
skp1:	RDAX	REG0,	1.0		; Read the contents of REG0 into the ACC
		WRAX	DACL,0		; Write to the left channel of the DAC
The problem i'm having, however, is that the ADC registers never seems to contain an exactly zero value, and so the skip never happens. I guess there's enough noise on the input to prevent it from truly zeroing out? As far as I can tell from the documentation, the ADC registers contain 24-bit numbers, where the MSB is a sign bit and the remaining 23 bits contain the number. I tried masking off the 8 LSBs and the sign bit of the register, but that didn't seem to help either.

So, my question is twofold: 1) Am i correct in my assumption that noise is the problem, or am i missing something obvious about how the ADC represents values/functions? 2) Is there an easy way to filter/modify the ADC value such that it'll actually reach zero when there's no input signal, or should i try another approach?

Thanks in advanced for any help!
frank
Posts: 1244
Joined: Wed Oct 19, 2005 12:26 pm
Contact:

Re: Using ADC value with SKP instruction

Post by frank »

There is always noise in an ADC signal, no way around it. Try the following:

1. Read in ADC and take absolute value so always positive
2. Low pass filter it, basically we want the envelope.
3. Select a threshold value (i.e. 0.1) so that above this value is considered signal and below is considered no signal
4. Do low pass result - threshold
5. Do a jmp neg since the value will be negative if signal is below threshold and positive is equal or above threshold
Frank Thomson
Experimental Noize
bennettcustomaudio
Posts: 5
Joined: Thu Sep 26, 2019 12:44 pm

Re: Using ADC value with SKP instruction

Post by bennettcustomaudio »

Hey Frank,

Thanks for the help! this worked perfectly! i had to play with the thresholding and the filtering a bit, but it's perfect!

Cheers!
JET
Posts: 15
Joined: Sun Aug 12, 2018 4:29 am

Re: Using ADC value with SKP instruction

Post by JET »

frank wrote: Thu Sep 26, 2019 2:03 pm There is always noise in an ADC signal, no way around it. Try the following:

1. Read in ADC and take absolute value so always positive
2. Low pass filter it, basically we want the envelope.
3. Select a threshold value (i.e. 0.1) so that above this value is considered signal and below is considered no signal
4. Do low pass result - threshold
5. Do a jmp neg since the value will be negative if signal is below threshold and positive is equal or above threshold
This would be very helpful for a project that I am working on, could you please post the code for this? I don't quite understand steps 2-4.
bennettcustomaudio
Posts: 5
Joined: Thu Sep 26, 2019 12:44 pm

Re: Using ADC value with SKP instruction

Post by bennettcustomaudio »

To user JET, here's a quick snippet of sample code. Essentially all i'm doing is taking the absolute value of the signal, applying a low pass filter at 60Hz, and then subtracting an offset of 0.004. If the resultant number is negative, then no signal is present. if it's greater than zero, then signal is coming in. hopefully this clarifies for you!

Code: Select all

		EQU	f2	REG0	; Envelop filter register
		EQU	fc_60Hz		0.011438928

		LDAX	ADCL		; Read in left channel of ADC
		ABSA					; Take absolute value of the signal
		RDFX	f1,	fc_60Hz	; Apply LPF at 60Hz to get envelop of signal
		WRAX	f1,	1.0	
		SOF	1,	-0.004		; If envelop of signal is less than 0.004,
		SKP	NEG,	 noSig		; Skip ahead to noSig

		; Insert code here that happens when signal is present ...
			
noSig:	; Insert code here for no signal present ...

JET
Posts: 15
Joined: Sun Aug 12, 2018 4:29 am

Re: Using ADC value with SKP instruction

Post by JET »

Thanks Bennett!

Yes this helps tremendously!
JET
Posts: 15
Joined: Sun Aug 12, 2018 4:29 am

Re: Using ADC value with SKP instruction

Post by JET »

Hey Bennett!

This seems to be working but every time the signal starts boarding the threshold (i.e. just a little be below and back above again) I get a slight crackling sound in one of my output channels.

Any thoughts on how to get rid of this?
bennettcustomaudio
Posts: 5
Joined: Thu Sep 26, 2019 12:44 pm

Re: Using ADC value with SKP instruction

Post by bennettcustomaudio »

JET wrote: Sat Jan 11, 2020 2:34 pm
This seems to be working but every time the signal starts boarding the threshold (i.e. just a little be below and back above again) I get a slight crackling sound in one of my output channels.
I'm not entirely sure what the problem may be. If you post some of your code i'd be happy to take a crack at it. Also, what's your hardware setup like?

It's also worth noting that I ended up increasing my threshold from -0.004 to -0.01 to account for stray noise that happened once I put the pedal in line with others on my board. So perhaps you could try increasing your threshold like I did?
Sweetalk
Posts: 141
Joined: Thu Oct 15, 2009 5:13 am

Re: Using ADC value with SKP instruction

Post by Sweetalk »

JET wrote: Sat Jan 11, 2020 2:34 pm Hey Bennett!

This seems to be working but every time the signal starts boarding the threshold (i.e. just a little be below and back above again) I get a slight crackling sound in one of my output channels.

Any thoughts on how to get rid of this?
I think that when the signal is near the threshold you'll have some artifacts due to some samples will fall below and others above it. You can try to fade in/out the signal slightly to minimize this effect. Something like when you place a noise gate in the effects chain and the signal is near threshold.
Post Reply