Store › Forums › Video Experimenter › General Discussion › Stuck on Interrupts
- This topic has 33 replies, 3 voices, and was last updated 13 years, 5 months ago by joey.
-
AuthorPosts
-
July 4, 2011 at 5:42 pm #1382MichaelKeymaster
Sounds like you’re making progress. Memory issues are frustrating because they can be nondeterministic and hard to debug. You will save space by storing your string literals in PROGMEM, so I encourage you to try that again. To access the string, you need to do it a bit differently than normal by using the function pgm_read_word.
Lots of explanation here: http://www.arduino.cc/en/Reference/PROGMEM
It makes most sense when your strings are longer than a few characters. If the string is short, then you don’t really save anything because you are using memory to store the pointers to the strings….
July 4, 2011 at 6:49 pm #1383joeyMemberWell, I got it working a lot better now although I feel dirty for not following better coding practices.
I’m getting incorrect output from the hour, minute, month, and day bytes though. This is new.
// This is an example of how to always present your callsign and other goodies on a VE
// Note that there is no known way to display the degree symbol as the char chart is different
// Also because of the VERY limited memory size on the Uno, this sketch had to be compressed
// from it's former glory.
// joey@stan4d.net
#include
#include
#include
#include
#include
TVout tv;
// You must use uart for this to work
// Create an instance of the TinyGPS object
pollserial pserial;
TinyGPS gps;
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// Your callsign
const char callsign[] = "NV0N";
//TMP36 Pin Variables
//the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade
//(500 mV offset) to make negative temperatures an option
const int temperaturePin = 0;
void setup() {
tv.begin(NTSC, 128, 98);
tv.set_hbi_hook(pserial.begin(4800));
initOverlay();
tv.select_font(font6x8);
tv.fill(0);
}
// Initialize ATMega registers for video overlay capability.
// Must be called after tv.begin().
void initOverlay() {
TCCR1A = 0;
// Enable timer1. ICES0 is set to 0 for falling edge detection on input capture pin.
TCCR1B = _BV(CS10);
// Enable input capture interrupt
TIMSK1 |= _BV(ICIE1);
// Enable external interrupt INT0 on pin 2 with falling edge.
EIMSK = _BV(INT0);
EICRA = _BV(ISC11);
}
// Required to reset the scan line when the vertical sync occurs
ISR(INT0_vect) {
display.scanLine = 0;
}
void loop() {
tv.delay_frame(1); // flicker prevention
// callsign
tv.select_font(font6x8);
tv.print(0,0, callsign);
while(pserial.available()) { // if there is data on the RX pin...
if(gps.encode(pserial.read())) { // if there is a new valid sentence...
getgps(gps); // then grab the data.
}
} // while
} // loop
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
char buffer[22];
PString message(buffer, sizeof(buffer));
float latitude, longitude;
// time, date, temp
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
message.print(hour);
message += ":";
message.print(minute);
message += " ";
message.print(month);
message += "/";
message.print(day);
message += "/";
message.print(year);
message += "Z ";
message += " ";
// temperature
// Fancy TMP36 calc which converts to Farenheit and then clips to a 2 digit degree
int temperature = int(((((analogRead(temperaturePin) * .004882814) - .5) *100) *1.8) +32);
message.print(temperature);
message += "F";
tv.select_font(font4x6);
tv.print(0,75, message);
// we're going to reuse the buffer so we need to clear it
message.begin();
// coords, alt
gps.f_get_position(&latitude, &longitude);
// let's process!
message.print(latitude);
message += ", ";
message.print(longitude);
message += " ";
int altitude = int(gps.f_altitude());
message.print(altitude);
message += "M";
tv.print(0,85, message);
}
July 4, 2011 at 6:54 pm #1384joeyMemberyay working. Just wrapped it in INTs
// This is an example of how to always present your callsign and other goodies on a VE
// Note that there is no known way to display the degree symbol as the char chart is different
// Also because of the VERY limited memory size on the Uno, this sketch had to be compressed
// from it's former glory.
// joey@stan4d.net
#include
#include
#include
#include
#include
TVout tv;
// You must use uart for this to work
// Create an instance of the TinyGPS object
pollserial pserial;
TinyGPS gps;
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// Your callsign
const char callsign[] = "NV0N";
//TMP36 Pin Variables
//the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade
//(500 mV offset) to make negative temperatures an option
const int temperaturePin = 0;
void setup() {
tv.begin(NTSC, 128, 98);
tv.set_hbi_hook(pserial.begin(4800));
initOverlay();
tv.select_font(font6x8);
tv.fill(0);
}
// Initialize ATMega registers for video overlay capability.
// Must be called after tv.begin().
void initOverlay() {
TCCR1A = 0;
// Enable timer1. ICES0 is set to 0 for falling edge detection on input capture pin.
TCCR1B = _BV(CS10);
// Enable input capture interrupt
TIMSK1 |= _BV(ICIE1);
// Enable external interrupt INT0 on pin 2 with falling edge.
EIMSK = _BV(INT0);
EICRA = _BV(ISC11);
}
// Required to reset the scan line when the vertical sync occurs
ISR(INT0_vect) {
display.scanLine = 0;
}
void loop() {
tv.delay_frame(1); // flicker prevention
// callsign
tv.select_font(font6x8);
tv.print(0,0, callsign);
while(pserial.available()) { // if there is data on the RX pin...
if(gps.encode(pserial.read())) { // if there is a new valid sentence...
getgps(gps); // then grab the data.
}
} // while
} // loop
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
char buffer[26];
PString message(buffer, sizeof(buffer));
float latitude, longitude;
// time, date, temp
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
message.print(int(hour));
message += ":";
message.print(int(minute));
message += " ";
message.print(int(month));
message += "/";
message.print(int(day));
message += "/";
message.print(int(year));
message += " UTC ";
// temperature
// Fancy TMP36 calc which converts to Farenheit and then clips to a 2 digit degree
int temperature = int(((((analogRead(temperaturePin) * .004882814) - .5) *100) *1.8) +32);
message.print(temperature);
message += "F";
tv.select_font(font4x6);
tv.print(0,75, message);
// we're going to reuse the buffer so we need to clear it
message.begin();
// coords, alt
gps.f_get_position(&latitude, &longitude);
// let's process!
message.print(latitude);
message += ", ";
message.print(longitude);
message += " ";
int altitude = int(gps.f_altitude());
message.print(altitude);
message += "M";
tv.print(0,85, message);
}
July 4, 2011 at 7:02 pm #1385joeyMemberI still get some artifacts every 10 seconds or so at the bottom of the screen. I can’t tell if it’s losing tracking or something else is going on. All the text moves to the right.
-
AuthorPosts
- You must be logged in to reply to this topic.