weird arduino behavior

Thread Starter

smp4616

Joined Oct 31, 2019
30
having some weird behavior on this code, I'm trying to implement a relatively slow shift out method for an arduino uno, I'm piggybacking on timer0 using the compa and compb interrupts to generate my clock signals, just testing this on my scope I wind up with a tiny 2uS spike about 200uS before the first actual clock edge, and there are 2 total complete clock pulses showing on the scope, not including the spike. running out of ideas on this one... the top code segment is my .cpp class file and the lower code is the arduino sketch

C++:
#include "Arduino.h"
#include "sendCommand.h"

SendCommand command;

ISR (TIMER0_COMPA_vect){            //use the timer0 module without changing prescalar or overflow interrupt
    PORTB |= 0b00000001;            //SET PORTB:0 TO HIGH (CLOCK)
}
ISR (TIMER0_COMPB_vect){
    PORTB &= 0b11111110;            //set portb:0 to low (clock)
    command.incBitCount();            //increment bit count
    
}


SendCommand::SendCommand(){            //default constructor, set up interrupts and pin directions here
}

void SendCommand::init(){            //run this in the setup loop of the program to set registers for timing
DDRB |= 0b00000011;                    //set arduino pins 8 and 9 to output
PORTB &= 0b11111100;                //set arduino pins 8 and 9 to low 
OCR0A = 0x2F;
OCR0B = 0xAF;
TIMSK0 &= 0b11111001;                //TURN OFF TIMER0 COMP INTERRUPTS (STOP CLOCK SIGNAL)
}

bool SendCommand::send(byte dataByte){            //this method will send the data until its buffer is empty then return 1 for completion
    TCNT0 = 0;
    OCR0A = 0x2F;
    OCR0B = 0xAF;
    //TIFR0 = 0;
    TIMSK0 |= 0b00000110;                        //enable interrupts (start clock signal)
    bitCount = 0;                                //reset bit count
    
    

    while (bitCount < 3){
    }                                            //sit and wait until interrupts send 8 bits
    TIMSK0 &= 0b11111001;                        //DISABLE INTERRUPTS (STOP CLOCK SIGNAL)
    PORTB &= 0b11111100;                        //set data and clock lines low
    return 1;                                    //return with completion flag
}

void SendCommand::incBitCount(){
    bitCount++;
}









#include "sendCommand.h"

void setup() {
  command.init();

}

void loop() {
  delay(100);
  command.send(56);
}
 
Top