Jump to content

Beginner DOUT/LED Question, Need Help


altech0000
 Share

Recommended Posts

I really hate to start another thread about DOUTs as I really thought I had this figured out but I apparently haven't. What I have is the core module and a DOUT module from smashtv. I have finally gotten the compiler to work after following the wiki and this link http://www.midibox.org/forum/index.php?topic=7238.0. I was able to compile the skeleton without any trouble. What I am trying to do is turn on 8 different relays depending on which note is send by midi (notes being C4 to C5 no sharps or flats). I started out simple by just writing the program to turn on the LED on DO and VS of the DOUT module when a midi event was received. Here is the program:

// $Id: main.c 333 2008-05-10 20:49:56Z tk $
/*
 * MIOS SDCC Wrapper
 *
 * ==========================================================================
 *
 *  Copyright (C) <year>  <name> (<email>)
 *  Licensed for personal non-commercial use only.
 *  All other rights reserved.
 * 
 * ==========================================================================
 */


/////////////////////////////////////////////////////////////////////////////
// Include files
/////////////////////////////////////////////////////////////////////////////

#include <cmios.h>
#include <pic18fregs.h>


/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after startup to initialize the 
// application
/////////////////////////////////////////////////////////////////////////////
void Init(void) __wparam
{
	// set shift register update frequency
  MIOS_SRIO_UpdateFrqSet(1); // ms

  // Up to 4 DOUTX4 modules (=16 shift registers = 128 digital outputs) can be connected
  // set the maximum number here - it doesn't really hurt!
  MIOS_SRIO_NumberSet(4);

}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS in the mainloop when nothing else is to do
/////////////////////////////////////////////////////////////////////////////
void Tick(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is periodically called by MIOS. The frequency has to be
// initialized with MIOS_Timer_Set
/////////////////////////////////////////////////////////////////////////////
void Timer(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when the display content should be 
// initialized. Thats the case during startup and after a temporary message
// has been printed on the screen
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Init(void) __wparam
{
  MIOS_LCD_Clear();
  MIOS_LCD_CursorSet(0x00);
  MIOS_LCD_PrintCString("Hello World!");
}

/////////////////////////////////////////////////////////////////////////////
//  This function is called in the mainloop when no temporary message is shown
//  on screen. Print the realtime messages here
/////////////////////////////////////////////////////////////////////////////
void DISPLAY_Tick(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
//  This function is called by MIOS when a complete MIDI event has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{

  MIOS_DOUT_PinSet(0, 1);

}
/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has been received
// which has been specified in the MIOS_MPROC_EVENT_TABLE
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyFoundEvent(unsigned entry, unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI event has not been completly
// received within 2 seconds
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyTimeout(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a MIDI byte has been received
/////////////////////////////////////////////////////////////////////////////
void MPROC_NotifyReceivedByte(unsigned char byte) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS before the shift register are loaded
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Prepare(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS after the shift register have been loaded
/////////////////////////////////////////////////////////////////////////////
void SR_Service_Finish(void) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an button has been toggled
// pin_value is 1 when button released, and 0 when button pressed
/////////////////////////////////////////////////////////////////////////////
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when an encoder has been moved
// incrementer is positive when encoder has been turned clockwise, else
// it is negative
/////////////////////////////////////////////////////////////////////////////
void ENC_NotifyChange(unsigned char encoder, char incrementer) __wparam
{
}

/////////////////////////////////////////////////////////////////////////////
// This function is called by MIOS when a pot has been moved
/////////////////////////////////////////////////////////////////////////////
void AIN_NotifyChange(unsigned char pin, unsigned int pin_value) __wparam
{
}

As you can tell this is just the skeleton wrapper with the Init and Event modified. This didn't work. I have tried various different things, even putting the MIOS_DOUT_PinSet(0, 1); statement in the Init section, hoping to get the light to turn on when I power the board up. No success. Now for the rest of the details:

  • R5 DOUT board from smashtv
  • R4 CORE board from smashtv
  • The PIC16F452 was bought separately and I programmed the bootloader and then uploaded MIOS via MIOS Studio
  • Every time I power up the board I get the one sysex message.
  • After that I did a hex upload of the compiled program above
  • If you look at the CORE board with the midi connectors facing away from you I have wired the CORE to the DOUT in left to right order when the DOUT is facing so the J1 is the farthest from you but on the inside row of J1 (if you need a pic let me know)
  • The led will flash once when I plug in the power supply to the CORE but will never turn on again
  • For the initial "led comes on when a even is received" the keyboard from MIOS and the keyboard from MIDI-OX were used to send the midi command 90 3C (note on, C4)

I am really amazed at all this board can do, I really want to build a SID even thought I don't know what it is used for right now. I'm not new to electronics only to midi circuits and midi music creation. I know it will be a while before I even attempt at making a SID or begin to understand what it does though I will keep reading until I do because this site and project really intrigues me. I really would have looked for about another two days before asking this question but I am working on this project for a friend and is due in about seven days.

PS In case your wondering, the application for this project is for my friends finial project for a visual arts, He was allowed to choose anything he wanted and get help from people to build it, the only requirement was that it contained lights. What he wanted to do was have a light show that was programmable by some software on the computer and have it flash lights to the music played. I have been experimenting with microcontrollers and doing electronics (for about four years on the general electronics and about a year in microcontrollers, just a tinkerer, nothing big, one past project, wireless gate opener) and I suggested he use midi so that is how I found this site. The light show will work like this: He will program the light patterns into a MIDI track in Sony Acid using the notes mentioned above then it will output it to the CORE and it will translate to a digital output via the DOUT module which will then switch opto-coupled triacs to control six 120VAC 50W light bulbs.

Thanks for any help you have to offer as it will be greatly appreciated,

Albert

Link to comment
Share on other sites

Sounds like a fun project. Don't worry about opening threads to ask for help, that's what the forum is for!

Did you use smart mode and wait for upload request when you loaded mios? Try it again, anyway.

If your bootloader is a bit kooky, it's possible that it starts mios and then dies. If you have it send a midi note when it receives one, does it work?

I can tell you've had a look around, don't forget the Troubleshooting section of the Download page on ucapps.de. The SRIO interconnection test could help.

Assuming your SR chain is working after that, you might like to try this:

for (i = 1; i < MIOS_SRIO_NumberGet(); i++) {

MIOS_DOUT_SRSet(i,0xff);

}

Should light em all up, in case you've got the led on the wrong pins....

Maybe the LED is the wrong way around? On that note, I didn't quite understand your description of the wiring, but theres a simple answer to that - make it match the schematics. If it does, it will work :)

Link to comment
Share on other sites

Yea I really have fun with these types of things.

Yes I did use smart and wait, re-uploaded mios again though. Just to make sure I am doing this right, when I upload my compiled hex file, I don't use the wait do I? and am I supposed to wait longer than 2 seconds before I start the upload?

I saw that test on the forum before and I wondered what they were talking about, now I know.

Just wrote a program to echo the midi input, tried it with this code but it didn't work:

void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{

	MIOS_MIDI_TxBufferPut(evnt0);
	MIOS_MIDI_TxBufferPut(evnt1);

}

Then I thought that maybe you had to send it in 3 byte increments, added evnt2 to that list and it works, I press a key on the keyboard and it echos back to the midi in. Finally something that works.

This is a picture (a poor picture) of how the DOUT board is hooked up to the CORE. Note: The red lines only hook to the second row of pins on the J1 header of the DOUT board, not both rows. (Sorry about the quality, don't really like paint)

Hookup.jpg

Hope this clears it up a little.

I haven't tried the SRIO or your code yet, I will be trying that in about two or three hours. One question, what is the purpose of 0xff in the MIOS_DOUT, I thought that is should be either 0 or 1.

About the led, I don't think it is backwards because it will briefly flash when the board is powered up though I will definitely try it.

I have now tried the SRIO test, that works, I get 5 volts at each pin on each modulation.

I tried your code and that works. Now the problem is if I replace the i in MIOS_DOUT with a 0 (Pin D0) then the light won't turn on.

Thanks for the help,

Albert

Link to comment
Share on other sites

Yes I did use smart and wait, re-uploaded mios again though. Just to make sure I am doing this right, when I upload my compiled hex file, I don't use the wait do I? and am I supposed to wait longer than 2 seconds before I start the upload?

Use smart mode and wait for request, always. It sounds like you're doing it wrong, you don't wait for anything.

midibox OFF

mios studio...

smart mode ON

wait for request ON

select your hex file

click the start upload button

mios studio says it's waiting for the upload request

turn on midibox (at which point it will send the upload request)

everything should upload automatically

Just wrote a program to echo the midi input, tried it with this code but it didn't work:

Then I thought that maybe you had to send it in 3 byte increments, added evnt2 to that list and it works, I press a key on the keyboard and it echos back to the midi in. Finally something that works.

Yeh, the two bytes may not be (weren't) a valid midi message. Check out the brainwashing centre. Anyway your core seems healthy :)

One question, what is the purpose of 0xff in the MIOS_DOUT, I thought that is should be either 0 or 1.

That's SRSet not PinSet - it sets all 8 pins on the SR in one go, 0xff == 11111111 == all on :)

That code does that for all your SRs (you have it configured for a single DOUTx4 module so 4 SRs, and no DINs, at the moment)

Link to comment
Share on other sites

Okay I edited my post above so check that out again.

Now, I will start doing it that way, I have been doing it several different ways, that being one of them.

Your code works, I press a key on the keyboard and the led comes on. The problem I am having now is getting pinset to work. If I write it like this, MIOS_DOUT_PinSet(0,1) then the led won't come on when I press a key.

At least I am making progress.

Link to comment
Share on other sites

Right, so your SRIO is good, your LED is not connected to pin 0. I think I know what this is, and if you look on the forum for posts about the SRIO chain, you'll find one from this week.

It's best not to edit a post once it's been replied to, makes things a bit confusing. I had to re-read your whole post again, to find out what had changed, and it was all for two lines. Better to just post the two lines of update in a new post ;)

Link to comment
Share on other sites

Sorry about the whole editing thing, I really didn't mean to do it that way, I posted and then performed another quick test and was going to edit it in there, well it took me some time to do it and after I had finished editing it, I realized that you had posted again. I usually mark it with an EDIT: but I didn't this time.

Also sorry about not posting earlier, my grandmother got sick and we had to take her to the hospital, I just got back about thirty minutes ago and just got everything wired up to fully test my theory.

Skip if you don't want to hear ramblings

After about ten minutes in the hospital I got to thinking on my circuit, I knew the SRIO is good and your code worked when it was turning on all the pins so it couldn't be the designed hardware so it must be my wiring. After getting back I looked at the board and realized the error of my thinking. when I was assembling the DOUT board, after I go the second to last header soldered in I notice a DO on that header (what I didn't realize was that was header J6), without looking or thinking I assumed that the pins would be labeled D0 through D32, and only looking at the one header the whole time I never realized that every header had a D0 through D7. So when trying to turn on the led at D0, the led was actually on D32 (Pin 31). After looking I noticed that the headers all had D0-D7 on them, then I looked at the header number and thats when I figured it out. I hooked the led to DO of J3, still didn't work, then I remeber looking over the forums that thats when I remeber some post about the boards being backwards, thats when I tried it on D7 and presto, it worked like a charm.

Okay we are back

Suffice to say that the led hooked up to the wrong pin, the exact opposite pin, was what was causing the problem.

Thanks for all your help, now I can rest a little knowing that I can finish his project.

Here is the finished code for the project.

void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{

	// a note event provides 128 different note values (0..127)
	// in this simple example, each note sets an individual pin
	// for DOUT pin numbers, see also this documentation:
	// http://www.ucapps.de/mios/mios_pin_list.txt

	int tempmyvar;

	switch ( evnt1 )
	{
		case 60:
			tempmyvar = 0;
			break;
		case 62:
			tempmyvar = 1;
			break;
		case 64:
			tempmyvar = 2;
			break;
		case 65:
			tempmyvar = 3;
			break;
		case 67:
			tempmyvar = 4;
			break;
		case 69:
			tempmyvar = 5;
			break;
		case 71:
			tempmyvar = 6;
			break;
		case 72:
			tempmyvar = 7;
			break;
		default:
			tempmyvar = 254;
			break;
	}

	if( tempmyvar == 254)
	{
	}	
	else
	{
		if( evnt0 == 0x80 || evnt0 == 0x90 )
		{
			// 90 xx 00 is the same like a note off event!
			// (-> http://www.borg.com/~jglatt/tech/midispec.htm)
			if( evnt0 == 0x80 || evnt2 == 0x00 )
			{
				// Note Off
				MIOS_DOUT_PinSet(tempmyvar, 0);
			}
			else
			{
				// Note On
				MIOS_DOUT_PinSet(tempmyvar, 1);
			}
		}
	}
}

here is a quick and dirty video of the board working (be sure to read the info below the video)

http://www.youtube.com/watch?v=GbEYbXMfoYE

Here you go Brian

Sorry for the poor quality, this is just a demo for the friend that this circuit was built for his project.

NOTICE: The lag that is in the video isn't there in real life, my camera just sucks.

For those of you who are not Brian:

I built the smashtv CORE and DOUT module kit. The triac board was just perfed. This is just a video of the channel status lights on the triac being controlled by the DOUT module that is being controlled by the CORE module that is being controlled by streaming midi commands from Sony Acid.

Lights programed by me in Acid in about ten minutes to the song In-a-gadda-da-vida by Iron Butterfly.

The triacs aren't acutally hooked up to the 6 50W light bulbs that board is mean't to hand, this is just the status lights.

Thanks so very much for all your help. I don't know if I would have figured it out in time had you not led me down the path you did.

Thanks for everything,

Albert

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...