ATtiny84, PCINT1_vect, Software Serial

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I have a routine running on an ATTiny84 the looks at pin change interrupts, calculates a frequency(RPM), measures temperature and toggles other output puts according to some logic. This works great.

 

Then I decided, wow, it would be great to see the state, temps and frequency.

 

So I wrote a bit of independent code that does the analog reads and outputs temps using softwareserial.

 

Software serial uses PCINT1 and I need PCINT1 to measure frequency, so these two bits of code won't compile together.

 

Everything with this case is happening pretty slowly, It would be perfectly fine to write out the stats I want every 5 seconds and shut down my PCINT1 while softwareserial is using PCINT1

 

The general routine I would like to be able to run:

  • my interrupts for a set period
  • then shut them off
  • start the softwareserial
  • output the data
  • end the serial
  • start my interrupts again

 

My question is, is there a way I can wrap my interrupt code with a conditional(like an if statement on a volatile variable) and get it inserted into the PCINT1_vect that the compiler is writing from the softwareserial?

 

And yes I did have to adjust OSCCAL to get the serial output to work reliably.

 

Thanks,

 

Bill

 

 

 

 

 

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This may be a bit late, but, pin change interrupts can be enabled for more then one pin on the port, to know which pin caused the interrupt to happen, you need to read and save the port pin state, so the next time the interrupt happens, you can xor the current port pin states with the saved state to know which pin caused the interrupt to happen, and then use an if statement or switch case to run the proper service function.

So in summary, with PC interrupts, you need to determine which pin caused the interrupt and then act as needed.

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

 

Thanks for the reply!

 

I ended up getting the two bits of code to compile together by commenting out the lines of code in the SW serial library that write the PCINT1 ISR vector. The PCINT1 ISR vector is only used to receive and I only need to transmit so no issues with deleting (or preventing) the SW's desire for  PCINT1. 

 

So the code runs for around 480 ms to determine RPM and then runs for 20 ms writing out the serial data. During the 20 ms I shut down the PCINTs by zeroing the mask, once the 20 ms has passed I use compare match B to re-enable PCINT1, then after 480 ms compare match A zeros the  PCINT1 mask, starts the serial TX, rinse repeat.

 

SW serial inhibits interrupts during a transmit. The duration of my transmits was on the order of 5 ms, so 20 ms window for transmit seems totally fine. I still have plenty of time in the remaining 480 ms cycle to get good data on RPM and I'm still supporting transmitting data out.

 

It works great!

 

 

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Glad to hear you got it working, and your solution, to only tx makes sense.

jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...