PDA

View Full Version : 12f675 and midi!



Alaskanphoenix
- 9th April 2006, 21:43
Hi!
I would configure a 12f675 to send midi messages, i know it is possible with the serout2 command, but the rate of midi is 31250 so i must use an external 20mhz crystal and bypass the internal clock.....How?

Thanks in advance

mischl
- 10th April 2006, 06:36
hi

cool project!

i did the same with an 16f876a once, here the most important settings :




DEFINE OSC 20 ' oscillator speed
define HSER_TXSTA 20h ' enable transmit register
define HSER_BAUD 31250 ' midi baud rate

hserout [$90,$45,$40] ' send a midi comand. noteon ch 1. middle A. middle velocity


this commands and defines are the same on a 12f675

eventually it would be possible to work with the debug command on the 12f675 and you could use the internal oscillator. must be tried. the debug command is the most fastest of the serial commands.
take a look at the pbp manual for setup the right debug settings.

I used this hardware setup (http://www.audiomulch.com/midipic/midicircuit.gif)

cheers

Alaskanphoenix
- 10th April 2006, 09:40
thank you mischl!

But the hserout command "Send one or more Items to the hardware serial port" and the 12f675 hasn't one!

I used this SerOut2 PORTB.3,12,[$B0,0,control] with a 16f84a and it's ok,but with 12f675 it doesn't work!

Any idea?

Ingvar
- 10th April 2006, 09:49
GPIO.3 is INPUT ONLY. Use a different pin and please read the datasheet. You probably need to disable AD and comparator aswell.

Alaskanphoenix
- 10th April 2006, 10:25
I used gpio.2 as output to send midi messages and i must use the gpio.0 and gpio.1 as ad inputs with pots!

I'm a beginner in pic programming,so please explain me how to configure these pins!

Thanks a lot

mischl
- 10th April 2006, 11:40
uuups. sorry, you are right, there is no uart at the 12f675 ;-)

look at the manual under SEROUT2 for calculating baud rate. 31250 baud needs a 20 mhz crystal.

for analog in : some sample program with a 12F675 (http://www.melabs.com/resources/samples.htm) look at TESTX4.BAS

Alaskanphoenix
- 10th April 2006, 22:29
I tried to use an external 20 mhz xtal with the serout2 but nothing!
Then i used the debug command with the internal xtal and finally some message appears but wrong,probably it can't reach 31250 baud! how can i disable the internal and use the external xtal?

mischl
- 11th April 2006, 11:56
please post your code si we can take a look

you can define the osc as usual, don't write any : @ DEVICE pic12F675, INTRC_OSC ' activates internal osc

how looks your serout2 command?

Ingvar
- 11th April 2006, 12:11
You set the use of an exernal oscillator in your programmer software, in your case you should look for HS oscillator. To make GP0 and 1 analog inputs, GP2 digital output and ADconverter 10bit, you should probably(never used the 12F675) use ....

TRISIO = %00000011
ANSEL = %00110011
ADCON0 = %10000001

ADvalue VAR WORD

ADCIN 0,ADvalue ' Read channel 0
ADCIN 1,ADvalue ' Read channel 1

Alaskanphoenix
- 11th April 2006, 14:14
I want to use gp0 and gp1 as analog inputs and gp3 as digital out to send midi messages:

DEFINE OSC 20
DEFINE DEBUG_BAUD 31250 ' midi baud rate
DEFINE DEBUG_REG gpio ' Set Debug pin port
DEFINE DEBUG_BIT 2 ' Set Debug pin bit
DEFINE DEBUG_MODE 0

adval var byte ' Create adval to store result
ANSEL = %00000011 ' ----DDAA
CMCON = 7 ' Analog comparators off

loop: ADCIN 0, adval ' Read channel 0 to adval
debug $b0,$00,adval
Pause 250 ' Do it all about 10 times a second
Goto loop ' Do it forever

End

how can i limit the results of analog inputs between 0-127?

Thanks a lot

mischl
- 11th April 2006, 14:56
divide adval by 2

adval = adval / 2
adval = adval >> 2

Alaskanphoenix
- 11th April 2006, 17:52
Thank you all very much!
It finally works!

I use the Hs oscillator and it works ok!

One last question, why if i connect a pot in gpio.0 and rotate it the numbers don't start from 0 but from $7f, go to 0 and arrive to $7f?

i use adval >> 2 to limit till $7F

Thanks

mischl
- 11th April 2006, 18:11
the pot values goes from 127 to 0 instead 0 to 127?

then change the plus and minus on your pot, that changes the direction

Alaskanphoenix
- 11th April 2006, 19:47
The pot starts from $7f, decreases till 0 and goes to $7f in the same direction!
But i used advar = advar >> 1 instead of >> 2, because the second starts from $3f to 0 to $3F!

Why?

TonyA
- 13th April 2006, 23:54
I'm also into MIDI. I've made a midi sender with the 18F452 and was wondering about the 12F683. But since it didn't have HSEROUT I wasn't sure if it would work. So it seems it can work with serout using a 20 Mhtz xtal?

Something I'm confused about however is the setting up of the ANSEL.
I see that in the example above by Ingvar there are 2 bits that are set high along with the appropriate pins: like this ANSEL %00110011, but in Allaskan's example he just does this: ANSEL %00000011

So GPIO.0 and GPIO.1 are analog inputs, but what do the 1's in position 4 and 5 represent?
What is the ADCON0 doing?

Also, why do you have to disable the analog comparators?

Thank,
Tony

Alaskanphoenix
- 14th April 2006, 10:42
HI Tony,
i used to send midi messages with the serout2 command at 31250 only with 16 and 20 mhz xtals and it works!

If you look at the datasheet of the 16f675 everything is revealed to you!

I think that ANSEL %00110011 sets the ad conversion clock to FRC and gp0 gp1 to ad inputs.

ADCON0 is the A/D CONTROL REGISTER, you use it if you want to set the conversion less automated.

I disable the comparators only for precaution!

bye

TonyA
- 14th April 2006, 13:19
Hi,

I was interested in your use of the 12Fxxx chip, and I noticed you used the DEBUG to send the midi messages out. Does the DEBUG work better than the serout2 for the 12Fxxx chip? (I'm interested in using the 12F683, I think you mentoned you used the 12F675?

Thanks again,
Tony

Alaskanphoenix
- 14th April 2006, 14:17
You are right,i mentioned the 12f675.I think there isn't much differences between the serout2 and the debug command,but my programming skill is low, i used both to send midi messages and they work ok!

TonyA
- 14th April 2006, 16:25
I see. I'll give it a try too. Thanks.