Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : PWM
Author | Message | ||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1805 |
I built a GPS clock with TFT screen. I used two colours Cyan backgroud with Blue foreground. The display was too bright at night so I implemented the touch to invert the colours but still too bright. I then used PWM to dim the display. I have 4 touch areas 2 to invert colours and 2 to dim the display. For the touch I use an interrupt. My problem was that the display was always dim. Took me a while to figure that every time the interrupt was called the display dimmed because I was using the top left corner of the display to dim. If Touch(x) < 180 and Touch(y) < 120 then Bright = Bright - 10 Bright being the variable in the PWM command. Problem was that without touching the screen Touch(x) and Touch(y) were -1 so the display dimmed. I have worked around by adding another line If Touch(x) < 180 and Touch(y) < 120 Then If Touch(x) > 0 Bright = Bright -10 EndIf Is this the way to go or is there a better way to do it. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I think it would be easier to make sure that no invalid values are accepted in the function. I use this 'defensive' style and it will save on extra tests in the rest of the function/subroutine making the code simpler and easier to maintain. [code] SUB TouchInterrupt() 'Invalid values will exit subroutine early 'My preference is a single line IF IF Touch(x) < 0 OR Touch(x) > MaxWidthValue then EXIT SUB IF Touch(y) < 0 OR Touch(y) > MaxHeightValue then EXIT SUB 'The rest of the code can now make use of values because they 'are in a valid range 'Here the rest of the code IF Touch(x) < 180 AND Touch(y) < 120 THEN Bright = Bright - 10 'If you sure nothing has to be done more exit the subroutine right away 'to prevent other code being run. In INTERRUPT routines you want to 'spend the least amount of time as possible. EXIT SUB ENDIF END SUB [/code] Microblocks. Build with logic. |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1805 |
Thanks Microblocks that's a big help. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1805 |
Ok the interrupt works fine and touching the screen varies the duty cycle up and down. Problem is the screen brightness does not vary with the duty cycle, it is all over the place. I'm sure it has something to do with the drive from the BC337. BigMick mentioned in his Backpack170 manual that he had problems and the resistor values were critical, which I don't thing they should be. I am thinking of driving a P Chanel MOSFET with the BC337 but can't find a circuit anywhere on the web. I can wire it up OK but would like a tried and tested circuit. Is anyone successfully using PWM and touch to control the backlight on an ILI9341 TFT. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5914 |
I made a couple of changes to Mick's circuit. I put the transistor the other way around - that is the 'correct way' I increased R6 to 1.2k and replaced R8 with two 1N914 diodes in series. That gives 3 diodes in series connected to the PWM pin. It is still sufficient to turn the transistor off when low and turn the transistor fully on when the pin is high. Jim VK7JH MMedit MMBasic Help |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2291 |
i recall this same discussion about the backlight driver from some time ago. the correct way to do things is to use a PNP transistor to switch the backlighting in the high side (+5v), and a second transistor that is an NPN to control the base of the PNP. the NPN transistor has its emitter connected to ground. any other approach is likely to produce unpredictable results. cheers, rob :-) |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8594 |
I now use this on all my PCBs: Gives complete flexibility on the PCB allowing fixed 3.3V, fixed 5V or PWM 5V depending on the display, with or without dropper resistor. Just populate the bits you need for any specific application and jumper the requisite shorting links with solder. |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2291 |
you could probably make R12 a much higher value if you wished, 330r will give a base current of (3.3-0.6)/330 = 8mA when turned on. 3k3 or even 10k should work equally well. cheers, rob :-) |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1805 |
Thanks to everyone, I will try with the Mosfet and see how it goes. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
palcal Guru Joined: 12/10/2011 Location: AustraliaPosts: 1805 |
I went with Jim's circuit as it was the easiest and it works fine. Thanks all. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Print this page |