Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

changing tris register fast and often?

Status
Not open for further replies.

justDIY

Active Member
I have an rgb led, common anode, and an 8pin PIC

I want to blink the rgb, in addition to having it change colors.

what I've come up with is setting the color I want on the output latches, and the blinking is performed by setting or clearing the TRIS registers for the respective bits. the blinking sometimes occurs as fast as a few khz.

the color of the rgb is controlled by a subroutine separate from the subroutine that is controlling the blinking.

so far, it is working great on the breadboard, but I'm wondering if there is some sort of long term effect, that may degrade the microcontroller?
 
I'd like to know where such a quaint notion comes from.

The only thing that I'm aware of in that category is the Flash program memory or the non-volitile data memory. I believe that both have a data retention time in the tens of years and a limit on the number of erase write cycles on the order of hundreds of thousands.

PIC output pins and registers? Toggle them all day long to your heart's content and be unafraid.
 
Well there's nothing wrong with setting the TRIS regs as often as necessary.

However, I'm a bit confused here. Normally for say an LED you'd put the anode on Vdd, then a resistor between the cathode and a PIC pin. The PIC turns it on when it's pulled low. Rather than turning it off by making it TRIS, you'd simply drive it high. When the pin is high there is 0v on the LED-resistor series string so it's off.

You could also put the LED string from PIC pin to ground so it turns on when the pin is high. However typically drivers pull down better (lower impedance) than pulling up due to the inherent technical differences between NMOS and PMOS transistors. So using the pull-down gets better performance.

TRIS is slightly unsafe in that the pin has reduced ESD protection. We like to set TRIS pins when there is something driving into the pin, like another IC. And it's just a bit odd.
 
Oznog said:
However, I'm a bit confused here. Normally for say an LED you'd put the anode on Vdd, then a resistor between the cathode and a PIC pin. The PIC turns it on when it's pulled low. Rather than turning it off by making it TRIS, you'd simply drive it high. When the pin is high there is 0v on the LED-resistor series string so it's off.

this is a compound device, the package has 1 anode and 3 cathodes ... so I am using 3 bits from the PIC, to control each cathode independently. There are resistors between each pin and the cathodes... so think of it as three leds wired in parallel, with their anodes tied together.

A little more detail ... the blinking is performed by reading the state of another pin... so I have a single bit controlling 3 bits. Forgive my lazyness, but this is the basic code:

Code:
If BlinkOPT = 1 Then 
        ' pass hdd input along to the pin direction registers
        TRISIO.0 = HDD
        TRISIO.1 = HDD
        TRISIO.2 = HDD
Else ' set pin direction as output
        TRISIO.0 = 0: TRISIO.1 = 0: TRISIO.2 = 0
EndIf

hdd is an alias (symbol) for gpio3 ... so the code reads 3 and sets 0:2 accordingly... it is an active low signal as well, so I want the rgb to be on when hdd is low, and off when it is high

the problem with changing the output drive I suppose is how my program is laid out... there are several different subs that might get called depending on conditions, all of which change the output drive to the RGB ... so one of them may change the drive, and then the blink routine goes and changes it to something else, which could lead to erratic blink operation

so I thought it would be safe to leave the output alone, and just change the pin direction register instead?

You could also put the LED string from PIC pin to ground so it turns on when the pin is high.

this might be an option in the future, when/if I run out of the leds I have... but for now, these are nice display quality leds, and their internal wiring cannot be changed, at least, not by me.

TRIS is slightly unsafe in that the pin has reduced ESD protection.

not sure I follow you here ... the way I read the diagrams from Microchip, the ESD protection diodes are always in place? I suppose having un-used pins set as high impedance inputs does minimize the chance the pic will have to swallow a surge?

And it's just a bit odd.

I like to think of it is a novel approach, rather than odd :lol:
 
Howdy neighbor,

I've done something similar (though never finished) using an 8-pin 12F683 running on the 8-MHz INTOSC...

There's many many different ways to accomplish the task and your method is probably as good as any other...

I used TMR2 generated 104-usec interrupts (every 208 instruction cycles) for bit-banged RS232 serial I/O and included the RGB PWM counters in the ISR as well... Each interrupt cycle I would increment the cyclic PWM period counter (cycling from 0 to 100) and compare it to the three Red, Green, and Blue PWM duty cycle counters (each set to some value between 0 and 100), turning an LED off with a counter match...

If I were to add blink control, I think I would just setup another counter in the ISR to count off 250 interrupts and toggle a 'blink' flag bit or mask for the RGB output pins (or to flip TRISIO bits)...

Kind regards, Mike
 

Attachments

  • rgbx_950.jpg
    rgbx_950.jpg
    100.1 KB · Views: 472
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top