Timer Interrupts - How to run code periodically?

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Timer Interrupts - How to run code periodically?

Postby Fuzzyzilla » Sun May 14, 2017 4:26 pm

Hello!
I am currently working on a library for an LCD. I am trying to make screen refreshes asynchronous. In order to do this, I would need to run the following code once every 500ns (125 cycles):

Code: Select all

//screenDat is of type  uint16_t[128*128]; Holds a copy of the screen's color data 
//readLoc is of type    byte*; Points to start of screenDat, reads it byte by byte (for speed)


//This function outputs screenDat one byte at a time via 8080 parallel
void LCD::tick(){//Updates the screen data. NO MORE OFTEN THAN ONCE EVERY 25 CYCLES(100 ns) - WILL BREAK EVERYTHING

	GPIO.out&=(~0b111111111111);                       //Unset all 8080 pins, CMD mode
	
	__asm__("nop\n\tnop");                             //Delay a little. May be unnecissary
	
	GPIO.out|=  0b011000000000|(*readLoc);             //Enable write and chip, write data, DATA mode
	
	readLoc++;                                         //Increment address, not value!
	
	if(readLoc==reinterpret_cast<byte*>(&screenDat+128*128*2))
	  readLoc=reinterpret_cast<byte*>(&screenDat);     //Reset readLoc to beginning if it reaches the end
}
I'm thinking the best way to do this is with timer interrupts, but I've never worked with these before.
Any help or advice? Is there maybe a better method?
Thanks!

P.S. I may also want to tune the frequency manually...

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Timer Interrupts - How to run code periodically?

Postby WiFive » Sun May 14, 2017 8:47 pm

Maybe i2s LCD Master Transmitting Mode w/ dma

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Timer Interrupts - How to run code periodically?

Postby Fuzzyzilla » Sun May 14, 2017 9:56 pm

I do not see how I2S applies for this at all...

The LCD is an 8080 parallel LCD that I want to use my own library for (So I could add some features that would be difficult to implement otherwise).

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Timer Interrupts - How to run code periodically?

Postby WiFive » Mon May 15, 2017 12:29 am

Because i2s has a parallel 24bit output mode

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Timer Interrupts - How to run code periodically?

Postby Fuzzyzilla » Mon May 15, 2017 2:06 am

Cool, I'll look into that. Does it support 8-bit parallel?
Just for future reference, however, does that mean that what I'm trying to do cannot be done?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Timer Interrupts - How to run code periodically?

Postby kolban » Mon May 15, 2017 4:48 am

Do these "I2S" component functions of the ESP32 in LCD mode (camera and LCD) have anything to do with any formal I2S protocol specifications? My guess (and that is all it is) is that the answer is no and that these parallel bus addressing capabilities needed a home in the ESP32 architecture and that the "I2S" component was close / chosen.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Timer Interrupts - How to run code periodically?

Postby Fuzzyzilla » Mon May 15, 2017 5:14 am

I think I found something promising in the ESP32 Arduino libraries.

Using the "timerBegin(timer, func, prescaler)" function, you can set up an interrupt that runs periodically.
Now I've just got to figure out what prescaler I need! According to the technical datasheet, it says "frequency=(80MHz/prescaler)" but in the examples it shows a prescaler of 80 resulting in a 1Hz clock (where the equation given says it should be 1MHz...). Hmm, contradicting information, my favorite :/

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Timer Interrupts - How to run code periodically?

Postby WiFive » Mon May 15, 2017 6:46 pm

Fuzzyzilla wrote:Cool, I'll look into that. Does it support 8-bit parallel?
Just for future reference, however, does that mean that what I'm trying to do cannot be done?
Yes "up to 24-bit" is what I meant. Maybe *can* be done but only *should* be done if you can't figure out how to do it with i2s.
kolban wrote:My guess (and that is all it is) is that the answer is no and that these parallel bus addressing capabilities needed a home in the ESP32 architecture and that the "I2S" component was close / chosen.
Pretty much

User avatar
Fuzzyzilla
Posts: 22
Joined: Sun Apr 23, 2017 3:19 am

Re: Timer Interrupts - How to run code periodically?

Postby Fuzzyzilla » Mon May 15, 2017 10:23 pm

Started looking into I2S.
It is not a parallel protocol, so it would be impossible to use for an 8080 parallel device such as this LCD(without a converter).

Unless, of course, I'm missing something, which is very possible!

I am using 8080 because of it's speed and simplicity (also because the LCD is wired that way :P )

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Timer Interrupts - How to run code periodically?

Postby ESP_Sprite » Tue May 16, 2017 1:16 am

It's probably somewhat confusing, but we're not saying you should address the LCD using the I2S *protocol*, we're saying you should use the I2S *peripheral* which in the ESP32 can do a lot more than talk I2S. Check the ESP32 technical reference manual, I2S section; it's called 'LCD mode' iirc.

Who is online

Users browsing this forum: No registered users and 132 guests