ATtiny85 Help

USB AVR Programmer and SPI interface. Adafruit's USBtinyISP.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jengil
 
Posts: 12
Joined: Wed Oct 02, 2013 11:41 pm

ATtiny85 Help

Post by jengil »

Hello,

I have an ATtiny85 (with the tiny programmer) and an Adafruit brass liquid flow meter which I am trying to interface. I have the brass flow meter working properly with an Arduino Uno, but when I move things over to the tiny interface things don't seem to work properly (I think based off of the timers/interrupts which I don't understand in the Tiny framework). The code in question that works on the Uno is as follows:

Code: Select all

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
  
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
  
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}
When I switch over to running it on the Tiny, I changed TIMSK0 to TIMSK as it says the timer register is referred to on the Tiny Datasheet. My idea was to flip a switch or close a valve when a certain amount of water has flown through the flow meter, and when I reach this amount nothing turns off using the same simple commands (digitalWrite) as with the Uno (that I have also used with the Tiny without issues before as well. I am quite confident that everything else in the code works so I just feel like the pulses are not being read properly. Any help or assistance will be much appreciated. Thanks ahead of time.
Last edited by adafruit_support_bill on Fri Jan 03, 2014 11:50 am, edited 1 time in total.
Reason: Please use the 'code' button when submitting code - click 'code' and paste your code between the tags.

Locked
Please be positive and constructive with your questions and comments.

Return to “USBtinyISP”