### Author Topic: Hysteresis, CV, and the TAPLFO  (Read 5852 times)

#### swinginguitar

##### Hysteresis, CV, and the TAPLFO
« on: September 30, 2011, 06:54:20 PM »
Been studying teh ASM code for most of the day. Just came across this:

; Apply hysteresis to the CV by checking if ADC_VALUE and ADC_VALUE+4 give the same result
addlw   D'4'      ; Add 4 to the AD value in W
andlw   B'11100000'   ; Get the top 3 bits (Result 1)
movwf   TEMP
andlw   B'11100000'   ; Get the top 3 bits (Result 2)
xorwf   TEMP, w      ; Test if the two results are the same
btfss   ZEROBIT      ; If zero, they're the same
goto   MainLoop   ; Not the same, no need to change multiplier

Could someone explain to me what it's doing, why, and how?

On another note concerning the TAPLFO code, in the main loop when he's checking the various CV inputs, it appears that only one CV per main loop is evaluated (rather than checking each one in turn per main loop) since after each one is checked there's a GOTO MAIN_LOOP instruction. Is the reason for this performance, best practice, or....? COuld you not poll each of teh CV inputs each iteration of the main loop? (perhaps it would make the PIC sluggish to do that many ADC's each time through?)

« Last Edit: September 30, 2011, 07:07:00 PM by swinginguitar »

#### slacker

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #1 on: October 02, 2011, 12:37:04 PM »
It stops the wave shape and multiplier jumping back and forth between setting as you turn the pot or due to noise or inaccuracies in the ADC. The ADC is 8 bit so you get values between 0 and 255, the wave shape is 3 bit (8 values) so the top 3 bits are used like this.

0 - 31 = wave shape 1 top 3 bits = 000
32 - 63 = wave shape 2 top 3 bits = 001
64 - 95 = wave shape 3 top 3 bits = 010

and so on. Even if you leave the pot in one position the ADC won't always give you the same value it will fluctuate a bit, so if you set the pot near the change from wave shape 1 to wave shape 2 you might get 30 one time and 33 the next so the wave shape will jump back and forth between the two settings. The code stops this happening like this,
30 + 4 = 34 so the top 3 bits are different so the code skips back to the main loop, leaving the wave shape set to what ever it was before. 33 + 4 = 37 so the top 3 bits are the same so it will change to wave shape 2, if it then reads 30 again next time it will ignore it and stay on shape 2. It basically creates gaps between the transitions where nothing happens.
« Last Edit: October 02, 2011, 12:38:57 PM by slacker »

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #2 on: October 03, 2011, 03:02:37 PM »
30 + 4 = 34 so the top 3 bits are different so the code skips back to the main loop, leaving the wave shape set to what ever it was before. 33 + 4 = 37 so the top 3 bits are the same so it will change to wave shape 2, if it then reads 30 again next time it will ignore it and stay on shape 2. It basically creates gaps between the transitions where nothing happens.

I was clear up until this paragraph - is it sorta double checking that the CV has stayed in the same range?

EDIT: nevermind...got it!
« Last Edit: October 03, 2011, 05:14:52 PM by swinginguitar »

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #3 on: October 12, 2011, 11:39:25 AM »
Any suggestions for visual feedback on the next multiplier button? would be nifty to have a series of LEDs  that light for each one in turn (quarter/8th/etc), but since there aren't nearly enough pins I assume this can't be done?

#### nexekho

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #4 on: October 12, 2011, 07:24:33 PM »
You could do that easily with three pins and a 4017.  Run one LED off each output of the 4017 all going to ground via a MOSFET you can use to turn the output on and off with a current limiting resistor too.  Pins are clock, light current LED and reset counter.

I don't know if this is a right way to do it?  I'm gonna experiment at Christmas with two 4017s and 11 MOSFETs to make a 20x5 LED matrix display for my Arduino.
I made the transistor angry.

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #6 on: October 13, 2011, 11:04:35 AM »
Would it work with 1 pin and an HEF4017BP like so:

Pic pin to 4017 clock input, 4017 reset tied back to the 4017 pin above where I want to reset (eg if i want 4 steps, tie the 5th pin to reset so it rolls itself over)

??

#### nexekho

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #7 on: October 13, 2011, 12:07:26 PM »
You want a manual reset line so if the Arduino resets you pull it high and the LED array syncs back up with the Arduino.  Otherwise you'd have to totally cut power to the whole circuit after programming.  You also need that transistor on the end otherwise you'd just be able to control the rate at which it lit EVERY led - it blocks the path to ground so you can switch the LEDs off.

But yes, you could tie an output to reset as far as I know.  You can't tie the pins together (it can cause problems) but if you want to lose some of the outputs, it can be done.
I made the transistor angry.

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #8 on: October 13, 2011, 12:17:01 PM »
You also need that transistor on the end otherwise you'd just be able to control the rate at which it lit EVERY led - it blocks the path to ground so you can switch the LEDs off.

without the transistor, each LED would light in turn at some fixed rate?

#### nexekho

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #9 on: October 13, 2011, 12:46:32 PM »
You also need that transistor on the end otherwise you'd just be able to control the rate at which it lit EVERY led - it blocks the path to ground so you can switch the LEDs off.

without the transistor, each LED would light in turn at some fixed rate?

Right, the LED will light if the 4017 gives out power and that power can get to ground via the LED.  The transistor's control input is hooked up to one of the outputs of the controller so it can block the path the ground.  I'm not 100% on this as I'm new to electronics and have no formal training in it but it seems to work on a simulator.  You will also need an appropriate current limiting resistor for the LEDs.

4017->LED->ground LIT!
4017->LED not lit
4017->open MOSFET->ground LIT!
4017->closed MOSFET->ground not lit

Again, I'm not 100% on this, it's probably better to ask someone on here with formal electronics experience.  Or possibly use a standard shift register.  There is an Arduino tutorial on using a shift register called ShiftOut.
I made the transistor angry.

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #10 on: October 13, 2011, 05:18:03 PM »
You want a manual reset line so if the Arduino resets you pull it high and the LED array syncs back up with the Arduino.

Would i be able to connect 2 sources to the rest (IOW, the PIC pin and the Nth pin on the 4017) so that I could reset it if either goes high? Or do they conflinct with each other with respect to 0v/5v?

Thanks for all the info....

#### nexekho

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #11 on: October 13, 2011, 06:39:49 PM »
I would assume you can but I don't know.  Never tried any of this and am not an expert.  Get a second opinion on everything!

Also, stick to existing shift register controlled dot matrix designs when possible.  Less to go wrong then.  Lots on Instructables.
I made the transistor angry.

#### slacker

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #12 on: October 14, 2011, 12:37:55 PM »
Would i be able to connect 2 sources to the rest (IOW, the PIC pin and the Nth pin on the 4017)

Yeah you can do this using Mickey Mouse logic connect a resistor from the reset pin to ground and then connect your sources to the reset pin using diodes, cathode to the reset pin anode to the source. This way if either of the sources goes high it will reset the CD4017 but the diodes isolate the sources from each other.

I think to do what you want you need 2 pins one to clock the CD4017 and one as a reset, you might get away without the reset, but at some point the CD4017 would probably get out of sync with the PIC. I would sacrifice the tempo LED and clock output pins and use those.
The pin to clock the CD4017 would simply have to send out a pulse when the next multiplier was pressed and the reset would reset the CD4017 when needed. Using these you can step through the multipliers and by resetting and then quickly clocking to the right place you can make the LED follow the multiplier CV pot.
« Last Edit: October 14, 2011, 12:41:16 PM by slacker »

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #13 on: October 14, 2011, 05:37:28 PM »
Thanks, gents!

I can definitely scrounge some pins off there - i won't be using several of the features of the chip and can re-direct those pins as outputs.

#### swinginguitar

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #14 on: October 18, 2011, 05:02:47 PM »
Using these you can step through the multipliers and by resetting and then quickly clocking to the right place you can make the LED follow the multiplier CV pot.

to quickly clock the 4017, obviously I need a series of quick pulses. Do you typically set the pin high, delay some small amount, then pulse it again? How long of a delay is needed typically for the IC to recognize a new pulse has fired?

#### slacker

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #15 on: October 19, 2011, 01:10:47 PM »
I don't know off hand, I think the CD4017 works at speeds up to 5Mhz or so. Check the datasheet that will tell you how long a pulse you need.

#### ElectricDruid

##### Re: Hysteresis, CV, and the TAPLFO
« Reply #16 on: October 19, 2011, 01:36:50 PM »
I like the idea, gents. Use a 4017 to give a visual indication of multiplier - nice.

It seems like it should be fairly straightforward the way you describe. Reset the 4017 to zero so you know where you are, then clock out enough pulses to get to the correct multiplier. This will be fast enough that poor old dopey humans will probably never even see what's happening. It takes us 20mS to spot *anything* which is hours in PIC-time.

Good luck with it. It's great to see these TAPLFO projects rolling!

Tom