Adafruit is open, safely ... and shipping all orders at this time! Read more!
0

Does this code conflict with the hardware serial port?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Does this code conflict with the hardware serial port?

by shobley on Wed Apr 08, 2009 5:25 pm

http://www.shaduzlabs.com/article-8.html

I just tried to wire in a MIDI input to this neat library, and the moment I tried to call init() on the oscillator library and Serial.begin() the Arduino crashed.

Does anyone know if stuff like this can break the serial port?

dutyCycleRegister = (dutyCycleValue/100.0)*ICR1;
OCR1A = dutyCycleRegister;

DDRD=0x00;
PORTD=0xFF;
DDRB=0xFF;

TCCR1A = (1<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<0)|(0<<0)|(1<<WGM11) |(0<<WGM10);
TCCR1B = (0<<ICNC1) |(0<<ICES1) |(1<<WGM13) |(1<<WGM12) |(0<<CS12) |(1<<CS11) |(1<<CS10);

TIMSK1=0x20;
TCNT1 = 0;
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 184
Joined: Fri Sep 07, 2007 5:16 pm

Re: Does this code conflict with the hardware serial port?

by shobley on Wed Apr 08, 2009 5:50 pm

I just tried it with the NewSoftwareSerial library and the same thing happens. So I suspect that maybe it does conflict.

Not sure why, as I thought it was just using the PWM hardware.

Does anyone know if this can be fixed?
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 184
Joined: Fri Sep 07, 2007 5:16 pm

Re: Does this code conflict with the hardware serial port?

by adafruit on Wed Apr 08, 2009 6:02 pm

softserial uses a timer, probably timer1

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Does this code conflict with the hardware serial port?

by shobley on Wed Apr 08, 2009 6:21 pm

Do you know if messing with timer1 breaks the hardware serial port?

I'm kinda bummed out about that.
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 184
Joined: Fri Sep 07, 2007 5:16 pm

Re: Does this code conflict with the hardware serial port?

by westfw on Wed Apr 08, 2009 7:26 pm

Define "hangs" - how do you tell?
TIMSK1=0x20;

You turn on timer 1 interrupts. Have you defined a timer 1 ISR handler somewhere? I'm pretty sure that the arduino core only defines timer0 and serial interrupts. (Why do you think that this breaks the serial port? Just because the arduino stops talking to the serial port?)

westfw
 
Posts: 1633
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Does this code conflict with the hardware serial port?

by mtbf0 on Thu Apr 09, 2009 8:36 am

couple of things.
Code: Select all | TOGGLE FULL SIZE
  DDRD = 0x00;
is going to set the serial port TX pin as an input. don't know what order things are happening, but if this is executed after the call to serial.Begin() it will break the serial port. i don't think it should cause a hang, but will definitely keep those bits from escaping your arduino.
Code: Select all | TOGGLE FULL SIZE
  TIMSK1=0x20;
enables a timer 1 output compare match interrupt. if you don't have an isr to catch it things will hang lickitysplit. if you just want the timer to turn OC1A on and off, there should be no need to enable the interrupt.
man, those timer settings would be a whole lot easier to read if you left out the bits you're not setting.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Does this code conflict with the hardware serial port?

by shobley on Thu Apr 09, 2009 12:18 pm

By hang I mean that the audio oscillator stops oscillating and the Arduino will not take a new program unless I power down and wait a few seconds.

This is not my library, but a very neat one all the same - if I can just make it serial port friendly I can dispense with all my other external oscillator stuff.

All this to play the Mario tune on a Tesla Coil. :D
http://www.stephenhobley.com
http://www.youtube.com/shobley
For all your laser harp, tesla coil, and killer robots from outer space needs.
shobley
 
Posts: 184
Joined: Fri Sep 07, 2007 5:16 pm

Please be positive and constructive with your questions and comments.