Pages: [1]   Go Down
Author Topic: Port type to use, output compare or normal digital?  (Read 665 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

I'm afraid this is going to have to be my first 'vague' post in that I can't yet divulge the exact nature of this project. However, I'm sure I can word the question perfectly well still. Amongst details, specific questions are in bold.

What I want to do, is when a counter running in my program reaches and/or exceeds a certain value, I want the chosen digital pin to go high for a set amount of time, and then go low again. But not as simply as that, please read on.

Now, I know if the program were as simple as that - one would probably just use a normal digital pin and use a timer like the micro function, however - I've got LOTS going on at the same time, as this is fairly time critical.

I know the PWM function is implemented using the Output Compare function which are located on specific pins, however - I'm not too sure how the PWM function actually works. I believe those pins run their own timer, so when a value is exceeded - the output is flipped. However, this timer is not one 'running in the main program'. So, does it sound like the above requirement could make best use of an Output Compare capable pin?

I suppose actually, what I am trying to ask - and have just realised it writing the above, is when that condition becomes true at which point I want an output to go high, I want this to generate some sort of "software interrupt" - in that the MCU pauses what it is currently doing and runs an ISR to switch the output on and then returns to the main program, where it can be turned off when another timer is exceeded. Are such "software interrupts" possible?

Or, using an Output Compare method as described above, the ISR that is run sets the pin high THEN sends the time for which the pin should remain high to the Output Compare pin. That way, the ISR sets the pin high - control is returned to main, then the Output Compare timer pulls the pin low after the time 'sent' by the ISR is reached.

I hope the above made sense!

EDIT: The reason I'm asking this here, and not in the programming section - is I'm decided which physical pin to use, which obviously determines board layout - thus being a hardware question.
« Last Edit: December 19, 2012, 02:44:57 pm by jtw11 » Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 146
Posts: 5535
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I know the PWM function is implemented using the Output Compare function which are located on specific pins, however - I'm not too sure how the PWM function actually works. I believe those pins run their own timer, so when a value is exceeded - the output is flipped. However, this timer is not one 'running in the main program'. So, does it sound like the above requirement could make best use of an Output Compare capable pin?

The timers can do lots of things. They have two compare registers so a pin can go high at one value and low at another. The datasheet has all the info.


I suppose actually, what I am trying to ask - and have just realised it writing the above, is when that condition becomes true at which point I want an output to go high, I want this to generate some sort of "software interrupt" - in that the MCU pauses what it is currently doing and runs an ISR to switch the output on and then returns to the main program, where it can be turned off when another timer is exceeded. Are such "software interrupts" possible?

Yes, definitely. The timers can generate interrupts as well as put signals on pins.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Brilliant, just the sort of good news I was after! Best get onto those 447 pages of the 2560's datasheet.

Quote
They have two compare registers so a pin can go high at one value and low at another.

Can you change these values continually whilst the program is running, as described - so that the ISR sets what time you want the output to toggle?

My apologies if that question is answered by the datasheet, it's difficult to know where to look in datasheets of this complexity, compared to the normal discrete component datasheets I'm used to!
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 146
Posts: 5535
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you change these values continually whilst the program is running, as described - so that the ISR sets what time you want the output to toggle?

Of course...

There's a couple of things to look out for but the datasheet covers them.

My apologies if that question is answered by the datasheet, it's difficult to know where to look in datasheets of this complexity, compared to the normal discrete component datasheets I'm used to!

Yes, the timers have a lot of options... smiley
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, sorry to revive a somewhat old thread - but after circumventing this problem, I am now at the stage in my project where I'm about to finalise board layout and start routing - clearly pin assignment is unavoidable now.

Quote
Yes, the timers have a lot of options...

So many options, that I'm struggling to get my head around them all.

It's obvious to me that the output compare pins are the ones used to generate a PWM waveform, using the output compare modulator with the timers.

I have 8 external devices that I want to switch on, and switch off with the highest level of time precision offered by the device, and so will use the timers for this as opposed to actual 'software'. Also an IC on the board with a pin that I must pull high / low with time criticality in mind.

I also need 8 PWM pins. So, I'm using the analog comparator for something else, so that knocks off pin 5 - OC3A/AIN1. So I'm left with 14 OC pins, and 17 'needs'.

The question is, the 9 time critical needs - I don't want to feed these a PWM signal, I just want to switch a pin high, or low at specific times. Can I not just use any pin for this, and do this within an ISR generated by the timers?
« Last Edit: March 15, 2013, 04:15:58 pm by jtw11 » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34243
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't want to feed these a PWM signal, I just want to switch a pin high, or low at specific times. Can I not just use any pin for this, and do this within an ISR generated by the timers?
Yes you can do that with any pin. If you get the PWM timer to trigger an interrupt you then use the ISR to count how many times it has been entered to time you pin's on and off.
Logged

UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's perfect! That opens up the potential for spare PWM channels!
Logged

Pages: [1]   Go Up
Jump to: