Showing posts with label bug. Show all posts
Showing posts with label bug. Show all posts

Thursday, October 12, 2023

DCO bug

 

I get some clickling when changing pitch (when not using an envelope)

This shows what is going on - when the new pitch is lower, the timer is not properly updated so it resets the pulse too early, before the wave has reached its maximum. Perhaps this could be fixed by simply letting the wave run until it is reset by the comparator?

Saturday, December 31, 2022

This year's x-mas gift from Mikroelektronika: A compiler bug

I have spent the last month chasing down an extremely strange bug. When I added a new global variable to my DCO, calibration stopped working.

I first spent a long time trying to figure out what was going on, and after a couple of weeks I ended up posting a rather vague description to the MikroC forums. 

What I was seeing was very weird - I had a double loop, and the inner loop ran fine the first time around but the second time the inner loop ran it skipped the first part. The outer loop was never re-executed but sometimes the program continued in the mail function afterwards.

I did a lot of testing but the results were always similar, some code was skipped and sometimes everything crashed. It felt like the program pointer moved to a different address. I started suspecting some kind of memory leak.

After the post in the forums I was asked to provide a minimal example - I normally do this anyway but this time I had a hard time doing so, as everytime I changed the program it started working.

Finally, I resorted to placing all variables and functions at absolute positions, as I suspected that some kind of memory collision was the problem. It took a looong time to get this right, and it wasn't always possible, but at last I managed to get a fully absolute-position program that still bugged in a similar way.

Now I gradually stipped the program down, re-running the code for every small change to make sure it still had the bug and that it could be brought back to working by moving something. I placed empty variables at absolute positions to prevent other, used variables from moving around, and also made sure that the empty spacers were not called upon anywhere in the code that was executed BEFORE the spot where the bug showed up.

This took me every spare moment from the 17th of December and the 13 days. Finally, yesterday, I had a minimal program with only a single function call inside the loop. Removing a single spacer variable made a single library variable (FLASH_write.savedINTCON) move too, and the program would start working. 

I was totally exhaused and posted a new question to the forums.

As I waited for answers, I used a diff tool to see if the two generated asm outputs from the working and non-working programs were different. They were not. I then did the same for the machine code listing file (.lst). Now I could see a single changed line! In the non-working version, a single instruction - MOVLB 0 - was missing. I took a screenshot and prepared to write a follow-up question.

When I logged in to the forum again, the user Janni had just posted an answer - and that was the exact same thing that I found. Janni confirmed that this was actually the error, the instruction changes RAM banks and when it is missing the function returns to the wrong part of the program, exactly what I was seeing.

Adding 'asm movlb 0;' after the call to FLASH_write fixes everything.

So here we are - it turned out to be a compiler bug after all. I am completely drained but incredibly happy that the error was found as I can't have any errors in the DCO.

Unfortunately, it seems Mikroelektronika stopped developing the MikroC compiler in 2019 so it is unlikely that the bug will ever be fixed. At least now I know what to look for if this ever happens again!

Happy new year everybody!

Thursday, July 2, 2020

JP6 Filter - error on PCB

I have managed to mess things up with the JP6 filter as well. I've drawn one single trace using layer 97 - info instead of the trace, so the left base of the cutoff CV expo converter is not connected to GND.

This is possibly the single worst place on the whole board to err, as the transistor IC is soooo tiny:





Update 7th of July: I found a second error, R22 should be connected to the negative mixing point of the resonance OTA (IC4A), not the junction between R19 and R19 (pin 1 of IC2A).

After fixing this, and realising I had used a 100k instead of a 10k resistor between the VCA CV and the mixing point (resulting in a +/-0.5V swing instead of +/-5V), everything works beautifully.

However, the output of the first cell has a swing of +/-5V when +/-6V is expected. This can be fixed by increasing the output gain, but it means that the 100k pot on the output op amp is maxed out. One needs to increase the value to have room for adjustment (adding a 22k series resistor probably fixes it). Not sure why the cell output is too low, this must be investicaged further

Update 8th of July: I found a third error... The output is fed back into the wrong pin on the overdrive OTA, meaning it attenuates instead of overdriving the signal. I also forgot about a resistor on pin 15.

In a new revision I should also consider again if the overdrive should happen pre-output VCA, now it is not possible to keep volume the same when overdriving, output is almost doubled when max overdrive is turned on.

Tuesday, June 16, 2020

Waveshaper bug

I finally got around to testing the waveshaper boards last week. Most of it work flawlessly though I get some clicking when doing large frequency jumps for some of the waveforms. Also, saw and sine waves are not as loud as the others at the same amplitude (which is to be expected I guess, I just need to consider if its ok).

For some reason though, two of the TL074 op amps got really hot and the sub oscillator didn't work. After some probing I found that the -2.5v source output 13.5v instead. I had my wife solder a second board but the same happened there.

I couldn't figure out what was going on, but it suddenly dawned on me when I tried to fall asleep yesterday - I have mixed up the op amp inputs when trying to make a voltage buffer :(

The fix is very easy in CAD, but on the boards I have to cut two lines and solder a new wire:

Cutting the input, it goes to the negative terminal of the op amp instead of the positive. I've also scraped away the solder mask to be able to add a new wire to the positive terminal instead. I will see if I can find a wire tiny enough to fit in the via (which is 0.3mm...). I also have to add a solder blob between the negative terminal and the output.

Cutting the feedback loop between the positive terminal and output. It should of course have been between the negative input and the output.


The board is smaller than it appears btw, here is my finger for reference.
UPDATE:
My wife managed to solder this just fine, after that the filter works flawlessly! The tiny diagonal wire is a single copper strand from a networking cable!


Sunday, October 1, 2017

Xonik DCO v1.0

The XDCO board arrived friday, and yesterday I soldered one to test it. I cannot find my 2N3904 SMD transistors for some reason, I was supposed to have received 100 of them in my last Farnell shipment but they were nowhere to be found. Instead, I had to modify a regular 2N3904 to fit the SMD footprint. It works fine but looks rather strange - and is of course not very durable. But for testing, it works just fine.

This wouldn't be a real Xonik project if the first version worked flawlessly however. After some initial problems programming the chip (I connected ISCP data and clock to SPI data and clock....), I discovered that I've used ISCP data as DCO CS, and NOT exposed it as a separate pin! That means that it is not possible to program the chip in circuit. I had to add a thin wire to expose pin 13 on the MCU. After doing this, everything worked as planned and I now have a working DCO.

The ISCP bug may be handled two ways:
- fix the bug and re-order the boards
- develop a boot loader and program the chips before soldering them into the circuit, then use SPI for programming later.

I've wanted to do a boot loader for a long time, so maybe this is the motivation I need - we'll see. The price of the board is not a big issue, they cost less than $20.

As for the crystals and speed - On the breadboard the crystals didn't start properly, resulting in fallback to the internal oscillator. I bought new crystals and did some proper calculation on what caps to use (the crystals require 18pF, using two 27pF in series should result in the correct value, see separate post) and now the crystals oscillate at the desired 32MHz right from the start.

Time to test the DCO with the waveshaper!

Update:
While the frequency is ok, the amplitude is off. The output maxes out at around 8.6V. If removing the cap, we get a flat 8.6V meaning something sinks the rest (?).  I tried removing the transistor collector, the opamp saturated to 15V so it is absolutely capable of delivering the necessary voltage. I also tried disabling resetting of the cap and even then the max was the same. The output stays at 8.6V even while programming the circuit. Someting is definitely wrong around the transistor.

BTW: I tried 5 different transistor and three variants of opamps on the breadboard and it still worked fine.

Update 2:
The amplitude issue was just a miswiring of the external transistor, I had mixed up collector and emitter. After changing this, calibration works again. There are some issues with timing and mcu crashes though, maybe related to unfiltered psu lines?

I've also tested and eliminated the 330k resistor from base to ground. it is necessary in the Juno 6 to keep the base voltage between 1.5 and -12.5 (from a 0 to 5v input) to control a PNP transistor. I am using an NPN which is on when the base is > 0.7V and off when the base is at GND, so it can be controlled directly without any biasing resistor. I've also checked the 68k value, it keeps the I_base high enough to allow I_c to be fully sunk while still being low enough to not damage the transistor.