timer issue

Store Forums Digit Shield Bugs/Problems timer issue

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #545
    gaggenau
    Member

    hi im working on a dmxtester device.
    i want to use a single potentiometer to set both channel and dmxvalue .a button to change between set channel mode and dmxvalue mode.
    to display the channel and dmx output value I want to use the digitshield.

    i have now start writing the code but when im compiling the sketch i get a strange error message:

    DigitShield/DigitShield.cpp.o: In function `__vector_9′:
    /Users/GET/Documents/Arduino/libraries/DigitShield/DigitShield.cpp:286: multiple definition of `__vector_9′
    DmxSimple/DmxSimple.cpp.o:/Users/GET/Documents/Arduino/libraries/DmxSimple/DmxSimple.cpp:141: first defined here

    it seems like the error has to do with the libraries im using. could it be a timer issue? or is it some other conflict?
    any ideas how to solve it?

    #include 


    #include

    int sensorPin = A0; // select the input pin for the potentiometer

    int DmxValue = 0; // variable to store the value coming from the sensor
    int buttonState = 0; // variable for reading the pushbutton status
    int ChannelValue=0;
    int RawValue1=0;
    int RawValue2=0;
    const int buttonPin = 7;

    void setup() {
    DmxSimple.usePin(6);
    DigitShield.begin();
    pinMode(buttonPin, INPUT);


    }

    void loop() {
    if (buttonState == HIGH) {
    // set Dmx channel
    RawValue1 = analogRead(sensorPin);
    ChannelValue = map(RawValue1, 0, 1023, 1, 512);
    DigitShield.setValue(ChannelValue);
    }
    else {
    // Set DMX value
    RawValue2 = analogRead(sensorPin);
    DmxValue = map(RawValue2, 0, 1023, 0, 255);
    DigitShield.setValue(DmxValue);
    }


    DmxSimple.write(ChannelValue, DmxValue);

    }
    #1301
    Michael
    Keymaster

    Yes, it looks like a timer conflict. The Digit Shield uses Timer 2 for the multiplexing of digits. If your DMX code doesn’t use Timer 1, I could show you how to change the Digit Shield library to use Timer 1 for the multiplexing.

    I’m pretty sure the initialization would be this:

      // TIMER1
    // Disable the timer overflow interrupt
    TIMSK1 &= ~(1 << TOIE1);

    // Set timer1 to normal mode
    TCCR1A &= ~((1 << WGM11) | (1 << WGM10));
    TCCR1B &= ~((1 << WGM13) | (1 << WGM12));

    // Disable compare match interrupt
    TIMSK1 &= ~(1 << OCIE1A);
    TIMSK1 &= ~(1 << OCIE1B);

    // Prescalar is clock divided by 128
    TCCR1B &= ~(1 << CS12);
    TCCR1B &= ~(1 << CS11);
    TCCR1B |= (1 << CS10);

    // Start the counting at 0
    TCNT1 = 0;

    // Enable the timer2 overflow interrupt
    TIMSK1 |= (1 << TOIE1);

    and the overflow ISR is this:

    ISR(TIMER1_OVF_vect) {
    TCNT1 = 0;
    for(int i=0;i digitShields->isr();
    }
    }
    #1308
    gaggenau
    Member

    Thanks!!
    Timer1 worked great.

    here is the finnish code:

    #include 

    #include



    int sensorPin = A0; // select the input pin for the potentiometer

    int DmxValue = 0; // variable to store the value coming from the sensor
    int ChannelValue=0;
    int RawValue1=0;
    int RawValue2=0;
    const int buttonPin = 7;

    void setup() {
    DmxSimple.usePin(6);// as standard the DmxSimple uses D3 but for this we need D7
    DigitShield.begin();
    pinMode(buttonPin, INPUT);
    digitalWrite(buttonPin, HIGH);


    }

    void loop() {
    int val = digitalRead(buttonPin);
    if (val == LOW) {
    // set Dmx channel
    RawValue1 = analogRead(sensorPin);
    ChannelValue = map(RawValue1, 0, 1023, 1, 512);
    DigitShield.setValue(ChannelValue);
    }
    else {
    // Set DMX value
    RawValue2 = analogRead(sensorPin);
    DmxValue = map(RawValue2, 0, 1023, 0, 255);
    DigitShield.setValue(DmxValue);
    }


    DmxSimple.write(ChannelValue, DmxValue);

    }
    #931
    vince
    Member

    Hi Michael,

    I’ve troubles with the use of and simultaneously and I think it’s due to the Timer part but I don’t know how I can fix this.

    the receiver is not receiving data if I setup “DigitShield.begin();” which is needed to drive the led segments.
    The receiver works and I can watch my data on the Serial if I bypass it “//DigitShield.begin();”
    Of course, the DigitShield library works great if I use it without VirtualWire.


    #include
    #include

    int i;
    int val;

    void setup(){
    Serial.begin(9600);
    vw_setup(9600);
    vw_rx_start();
    DigitShield.begin();
    Serial.println("Ready");
    }

    void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) { // check to see if anything has been received
    for (i = 0; i < buflen; i++) {
    val = buf;
    Serial.print("temp :");
    Serial.println(val);
    DigitShield.setValue(val);
    }
    }
    }

    Hope you will have suggestions.
    Regards
    Vince

    #933
    Michael
    Keymaster

    Does the virtualwire library use timer2?

    #934
    vince
    Member

    Hi Michael,

    thanks again for your help.

    Here is the Timer part of the VirtualWire.h library. I’m not very comfortable with this part of the code but I guess that it uses Timer1.

    I’ve download the VirtualWire Library v1.9 just here http://www.open.com.au/mikem/arduino/


    // Speed is in bits per sec RF rate
    void vw_setup(uint16_t speed)
    {
    // Calculate the OCR1A overflow count based on the required bit speed
    // and CPU clock rate
    uint16_t ocr1a = (F_CPU / 8UL) / speed;

    #ifndef TEST
    // Set up timer1 for a tick every 62.50 microseconds
    // for 2000 bits per sec
    TCCR1A = 0;
    TCCR1B = _BV(WGM12) | _BV(CS10);
    // Caution: special procedures for setting 16 bit regs
    OCR1A = ocr1a;
    // Enable interrupt
    #ifdef TIMSK1
    // atmega168
    TIMSK1 |= _BV(OCIE1A);
    #else
    // others
    TIMSK |= _BV(OCIE1A);
    #endif

    #endif

    // Set up digital IO pins
    pinMode(vw_tx_pin, OUTPUT); // currently configured to IO pin 12
    pinMode(vw_rx_pin, INPUT);// currently configured to IO 11
    pinMode(vw_ptt_pin, OUTPUT);// currently configured to IO 10
    digitalWrite(vw_ptt_pin, vw_ptt_inverted);// currently configured to IO 0
    }

    Sure you will understand this better than me ::)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.