Nerds assemble: programming the ATmega88PA?

What's Hot
OK, so this is tangentially amp-related, but...it's going in OT anyway.

I've got a three-channel preamp which uses an ATmega88PA-PU controller to take MIDI signals in and switch channels accordingly. The latency is about 400-500ms, which is unacceptable, so I need to experiment to find the shortest gap which doesn't include a massive "thump" (assuming the gap's there for noise suppression). I know that the gap is a function of the program running on the controller (spoke to the manufacturer).

So...I've been working on the pre-requisites for making some changes:

1 - I've got a TL866II unit to flash the controller.
2 - I've got Arduino IDE set up to use it (I think), and to handle the ATmega88PA.
3 - I have beer at the ready.
4 - The guy who built it is going to be sending me the original source code this evening.

My questions are...

1 - It seems like there are multiple options for setting the controller's clock, but the board in the preamp appears to have a clock crystal there already. Is there any easy way to find out which clock frequency it's set to use without going back to the guy to ask him?

2 - Can I tell it to ignore the external clock and use its internal clock instead? Is this even advisable?

3 - ...or am I going to have to simply try delay(10000) and reflash with different clocks until the delay is exactly 10s to work it out?
<space for hire>
0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
«1

Comments

  • joeyowenjoeyowen Frets: 4025
    Is there any reasons you can' t ask the guy (Especially for 1 and 2?)


    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • joeyowen said:
    Is there any reasons you can' t ask the guy (Especially for 1 and 2?)


    Mainly because he's Russian and his English isn't that good - however, I did and it's probably 8MHz, but maybe 20MHz. Looks like it's going to be experimentation ;)
    <space for hire>
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • MayneheadMaynehead Frets: 1782
    Do you really need to work out the clock rate? If you have the original source code, can you not simply locate the original delay value and keep halving it until you start to have issues?
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • Have you experience of this kind of code? I tried doing some PIC programming and it was massively different to any programming I'd ever done before. Logic is logic, but these things are so close to the hardware that you have to be really clued up on that side of things. In my case it was the fact that you only had limited 8-bit buses on which to set things on and off, and you needed to get a certain interval frequency or better in order to make LEDs appear steady to the human eye.

    And I was writing the code from scratch, in English. How's your Russian?
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • Or just do what I did and buy a better amp :D
    ဈǝᴉʇsɐoʇǝsǝǝɥɔဪቌ
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • digitalscreamdigitalscream Frets: 26560
    edited December 2018
    Maynehead said:
    Do you really need to work out the clock rate? If you have the original source code, can you not simply locate the original delay value and keep halving it until you start to have issues?
    Well, I could, but it'd be nice to get some sort of accurate calibration.

    Have you experience of this kind of code? I tried doing some PIC programming and it was massively different to any programming I'd ever done before. Logic is logic, but these things are so close to the hardware that you have to be really clued up on that side of things. In my case it was the fact that you only had limited 8-bit buses on which to set things on and off, and you needed to get a certain interval frequency or better in order to make LEDs appear steady to the human eye.
    Well, I haven't...but let's put it this way - I've been programming for about 30-odd years, and there are schoolkids who write programs for the Arduino, which have these chips at the core. On top of that, I'll be getting the source code this evening, and it's orders of magnitude more simple to alter existing code than it is to write from scratch even in an unfamiliar language.

    And I was writing the code from scratch, in English. How's your Russian?
    It's written in C, I believe, which is more of a universal language than English Point is, this isn't a complex program - I know it uses the existing Arduino MIDI.h library, which is blindingly easy to deal with. I'd be amazed if there were more than 50 lines of code involved, which makes it pretty easy to trace.

    Having dumped the contents of the IC in question, there are exactly 2016 bytes of program in there. It can't be that big or difficult to understand in its original form...can it?

    As an aside, I count it as a major win that I've managed to get the TL866II programming gadget to work under Linux! I suspect that'll actually turn out to have been a harder job than correcting the code...
    <space for hire>
    0reaction image LOL 0reaction image Wow! 1reaction image Wisdom
  • Or just do what I did and buy a better amp :D
    I did consider that, but these are the facts:

    1 - It really does sound great (it's a Soldano X88R clone)
    2 - Nobody else seems to do a decent clone, and none of them support MIDI
    3 - A real X88R with MIDI is rare enough that we're talking "house deposit" money, whereas this one cost me £350
    <space for hire>
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • monquixotemonquixote Frets: 17585
    tFB Trader
    What does the controller connect to?

    Could you switch it over to a contact closure relay and use a control out on the helix?
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • danodano Frets: 1590
    edited December 2018
    I didn't realise the ATmega88PA is used by any Arduino products ?  Without seeing the source code it's just guess work.

     Could be how he's implemented any delays, could be reading an IO pin instead of using a HW interrupt. Could be he's been dicking with the internal clock divide registers. 

    I use Atmel micros quite a bit so post questions if you need to know stuff
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • @digitalscream i was aware of your extensive programming experience, of course. Just checking you'd not jumped in thinking this would be as easy as building a RoR forum, without doing research first. And that's mainly because I made a similar mistake when trying to write code for a for alarm control panel in Assembler (with English names for stuff).

    Good luck.
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • dano said:
    I didn't realise the ATmega88PA is used by any Arduino products ?  Without seeing the source code it's just guess work.

     Could be how he's implemented any delays, could be reading an IO pin instead of using a HW interrupt. Could be he's been dicking with the internal clock divide registers. 

    I use Atmel micros quite a bit so post questions if you need to know stuff
    The ATmega88PA is basically the ATmega328 used in the Arduinos with only 8KB of memory - same core, and pin-for-pin compatible.

    @digitalscream i was aware of your extensive programming experience, of course. Just checking you'd not jumped in thinking this would be as easy as building a RoR forum, without doing research first. And that's mainly because I made a similar mistake when trying to write code for a for alarm control panel in Assembler (with English names for stuff).

    Good luck.
    Yeah...so I've got the source code. Oddly, it wasn't built using Arduino sketches the way I'd expected. This one has all of the MIDI and I/O implementation built from scratch, which I'll admit is more than I bargained for.

    That said, once I'd figured out that it was built using CodeVision (and that the eval version will work because the binary image is less than 4KB). The slight sticking point is that CodeVision doesn't support the programmer gadget I've got, which means I need to figure out how to get it to output a file format that the programmer's software can process. I believe I've got them both talking - Intel Hex appears to be the one - but I won't know until I've got the chip blanks tomorrow and I can try it.

    I've also figured out how it works and where the gap is generated (looks like both a pre- and post-switch delay), so I know what I need to change. Once I've done that, I think I'll probably have a go at porting the whole thing to a more-manageable Arduino sketch. That's not really necessary for what I'm doing right now, but it'll be handy for my next project - when I've got some time, I'm probably going to build a combined MIDI controller and loop switcher, with the added functionality of trails in the loops.

    As a total aside, I don't have the manual for the preamp. It's only from reading through the code (comments in Russian...yay...) that I've figured out how to save channel assignments per-patch :)
    <space for hire>
    0reaction image LOL 1reaction image Wow! 0reaction image Wisdom
  • MyrandaMyranda Frets: 2940
    Which ide are you using? AVR studio has a clock speed setting (my experience was with the ATMega8385 I think) and while it's an 8mhz chip it was unstable at that speed so we ran it between 1mhz and 4mhz.

    We also used ISP-U I think it was called and that too detected clock speed
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • Myranda said:
    Which ide are you using? AVR studio has a clock speed setting (my experience was with the ATMega8385 I think) and while it's an 8mhz chip it was unstable at that speed so we ran it between 1mhz and 4mhz.

    We also used ISP-U I think it was called and that too detected clock speed
    I'm stuck with using CodeVision (it has features required by the original firmware). Taking another look at the project settings and the code's clock divisor, it does seem like it's clocked at 8MHz.

    I'm gettin' there. The main question now is whether the file I've exported from CodeVision is properly compatible with the import for Xgpro (the burner software). Both reckon they're talking Intel Hex, but I'm naturally distrustful.
    <space for hire>
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • MyrandaMyranda Frets: 2940
    Maynehead said:
    Do you really need to work out the clock rate? If you have the original source code, can you not simply locate the original delay value and keep halving it until you start to have issues?
    Well, I could, but it'd be nice to get some sort of accurate calibration.

    Have you experience of this kind of code? I tried doing some PIC programming and it was massively different to any programming I'd ever done before. Logic is logic, but these things are so close to the hardware that you have to be really clued up on that side of things. In my case it was the fact that you only had limited 8-bit buses on which to set things on and off, and you needed to get a certain interval frequency or better in order to make LEDs appear steady to the human eye.
    Well, I haven't...but let's put it this way - I've been programming for about 30-odd years, and there are schoolkids who write programs for the Arduino, which have these chips at the core. On top of that, I'll be getting the source code this evening, and it's orders of magnitude more simple to alter existing code than it is to write from scratch even in an unfamiliar language.

    And I was writing the code from scratch, in English. How's your Russian?
    It's written in C, I believe, which is more of a universal language than English Point is, this isn't a complex program - I know it uses the existing Arduino MIDI.h library, which is blindingly easy to deal with. I'd be amazed if there were more than 50 lines of code involved, which makes it pretty easy to trace.

    Having dumped the contents of the IC in question, there are exactly 2016 bytes of program in there. It can't be that big or difficult to understand in its original form...can it?

    As an aside, I count it as a major win that I've managed to get the TL866II programming gadget to work under Linux! I suspect that'll actually turn out to have been a harder job than correcting the code...
    We had to use Atmel assembly for our project in our first year, then C in the second... Was much easier in C. 

    And I did a little reverse engineering of compiled software - it's something that needs more practice than I have it. Might do some more... 
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • <space for hire>
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • It only fucking works. Had a bit of a wobble with the first attempt - I hadn't set the fuse bits right, so it was going from the internal clock @ 1MHz instead of the external crystal @ 8MHz.

    Tried it at various ever-decreasing combinations...got it down to 2ms pre-delay and 2ms post-delay with no thump. I'd call that a massive fucking win!!!!!!!!!!!!
    <space for hire>
    0reaction image LOL 1reaction image Wow! 0reaction image Wisdom
  • Of course, now I have to think of something to do with the 10 spare chips I have. I've offered to burn them and send them out to any of his other UK customers...seems like the right thing to do.
    <space for hire>
    0reaction image LOL 1reaction image Wow! 0reaction image Wisdom
  • joeyowenjoeyowen Frets: 4025
    Fair play, sounds like you made easy work of it
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • joeyowen said:
    Fair play, sounds like you made easy work of it
    Well, kinda. I just discovered that there are separate functions in different parts of the code for handling front-panel channel switching and MIDI preset channel switching. Just had to bring the MIDI one in line with the front-panel one and burn it again.

    I really must stop assuming that everyone's going to write their code DRY.
    <space for hire>
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
  • monquixotemonquixote Frets: 17585
    tFB Trader
    Well done dude.
    0reaction image LOL 0reaction image Wow! 0reaction image Wisdom
Sign In or Register to comment.