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.

Questions on upgrading my Project

Status
Not open for further replies.
Yes, you can do what you like with the programme.

Have you tried to simulate it in MPLAB?

Yes, I was intending to suggest that you start a new thread in the Microprocessor section as more people with PIC expertise will see it there & be able to help you.

EDIT.
Do you have the 16F84 data sheet?

If so, the config word is on page 21 (I have the DS35007A version)
 
Last edited:
Yes, you can do what you like with the programme.

Have you tried to simulate it in MPLAB?

Yes, I was intending to suggest that you start a new thread in the Microprocessor section as more people with PIC expertise will see it there & be able to help you.

I haven't put it into MPLAB but will be doing so tomorrow. Then I will study it and follow up in a new thread in the desired section with any questions and as for now i'm gonna leave this thread alone.
Thanks for the response.

Response to EDIT:
Yes I do and will look at that.
 
Last edited:
After some thought about the PIC programme, I have made some minor changes to the circuit in order to make the programme simpler.
 
Tom,
Here is another simple programme that you may find of interest.

I wrote it some years ago for a friend who wanted a device that would switch a fan on for 1, 2, 3 or 4 hours - as set by a rotary switch.

The PIC is driven by a 32.768 kHz crystal. Therefore the PIC is operating at 8192 instructions per second.

The basic timing is done by TMR0. The prescaler is set to 256. So TMR0 is being incremented every 256/8192 = 31.25 ms.

TMR0 is loaded with the complement of the value required and it counts up. The overflow flag is set when it goes from FF to 00.

When the programme detects the overflow flag, it counts the event & and reloads TMR0.

So for a delay of 4 seconds, TMR0 is loaded with the complement of 128 (128 = 4/0.03125).

Code:
;Programme function - Operate a relay & release it after 1, 2, 3 or 4 hours.
;The timing is set by a rotary switch. Switch changes are detected by the 
; RB change interrupt function & cause the timer to restart from 0.
;Oscillator frequency = 32.768 kHz, Instruction rate = 32768/4 = 8192 Hz.
;TMR0 prescale = 256, so the frequency input to the TMR0 is 8192/256 = 32 Hz.
;If TMR0 is set to the complement of 16 (decimal) then it will overflow after
; approx 16/32 = 0.5 seconds.  
;If TMR0 is set to the complement of 128, it will overflow after 128/32 = 4 sec.

              LIST   P=PIC16F84,	F=INHX8M
            include "p16f84.inc"
             __CONFIG 0x3FF0	;32.768 kHz Crystal Oscillator, WDT off, Power up reset on

porta	equ	05	;input/output pins RA0 ~ RA4
portb	equ	06	;input/output pins RB0 ~ RB7

cblock 0x10				
	count1	;minutes counter (4 sec increments)
	count2	;hours counter (60 sec increments)
	temp
endc

#define relay	portb, 0	;relay connected to RB0

#define	tmr0_of	INTCON, 2	;TMR0 overflow flag
#define	sw_ch	INTCON, 0	;switch change (RB change flag)

	ORG	0x00		;set programme counter to 0

	call	init

	bsf		relay		;operate relay

restart 		;Starts from here after a switch change is detected
	bcf		sw_ch		;clear RB change flag

	call	delay_500m		;call 0.5 second delay to allow switch contacts to settle
	
	movlw	d'240'		;4 hour

	btfsc	portb, 4	;is rb4 high?
	movlw	d'60'		;1 hour

	btfsc	portb, 5	;is rb5 high?
	movlw	d'120'		;2 hour

	btfsc	portb, 6	;is rb6 high?
	movlw	d'180'		;3 hour

	movwf	count2		;count2 = 60, 120, 180 or 240
;the code below uses count1 & count2 to determine the relay on time.

loopb
	movlw	d'15'		
	movwf	count1		;4 sec * 15 = 1 minute
	
loopa
	call	delay_4s

	btfsc	sw_ch		;has a switch changed?
	goto	restart		;yes - restart to determine the new time setting

	decfsz	count1		;decrement count1 by 1, skip if 0
	goto	loopa		;count1 is not 0, so repeat

	decfsz	count2		;count1 is 0 , so decrement count2
	goto	loopb		;count2 is not 0, so repeat

	bcf		relay		;count2 is 0, so release relay
		
	sleep	;PIC goes into low power mode & does nothing
	NOP

;sub routines

delay_4s
	movlw	d'127'		;4 second delay @ 32.768 kHz
	goto 	$+2

delay_500m
	movlw	d'15'		;0.5 second delay @ 32.768 kHz
	movwf	temp		
	comf	temp, w
	movwf	TMR0
	bcf		tmr0_of

	btfsc	sw_ch		;has a switch changed?
	return				;yes - exit loop
	
	btfss	tmr0_of		;await TMR0 overflow
	goto	$-1
	return

init
	bsf		STATUS, 5	;selects BANK 1

	clrf	TRISA		;make RA0:4 outputs

	movlw	b'01110000'	
	movwf	TRISB       ;RB0:3,7 outputs  RB4:6 inputs
                
	movlw	b'10000111'	;sets prescaler to 256, internal clock
	movwf	OPTION_REG	
		
	bcf		STATUS,5	;selects bank 0

	clrf	INTCON
	clrf	porta		;clears porta
	clrf	portb		;clears portb

	bsf		INTCON, 3	;RB change enable
	bsf		INTCON, 5	;TMR0 overflow enable
	return

	end
 
Questions on upgrading my Project**UPDATE**

Thanks to the directions of ljcox I have been able to now see how I am going to tackle my project here.

As discussed earlier in this thread, I had some questions about how to drive my 15 cathode columns and sink my 7 anode rows for my 15x7 moving display. My original source(talkingelectronics.com) has things different than the parts I have. They used leds and I wanted to use the mis-ordered 5x7 display modules I have.

Well I'm working on this slowly and surely as my brain will allow...lol.

This may be hard to understand but links to my sources and pics and video and asm's will hope to help you.

Like I said its gonna take some time for me to get the whole picture, but, i'm working on it and starting with 4x4 first.

Thanks and comments and questions are invited.

sources:

https://www.electro-tech-online.com/custompdfs/2012/03/LTP2157AKx.pdf

http://thevaportrail.com/pr/01_Crossbar/crossbar.html

http://talkingelectronics.com/projects/15x7Display/15x7Display-1.html

((((MY VIDEO)))) http://www.youtube.com/watch?v=5A0r...DvjVQa1PpcFMlfgyZB2D2V1EDM1gnMnbJqpNKvxfCRY8=
 

Attachments

  • IMG_0027.JPG
    IMG_0027.JPG
    314.2 KB · Views: 150
  • Crossbar.asm
    55.9 KB · Views: 142
  • 4².asm
    55.9 KB · Views: 132
Very good.

Now I can see what it does.

There is a lot in the .asm files that I have not used or knew was possible, eg. Macros & if functions.
 
Very good.

Now I can see what it does.

There is a lot in the .asm files that I have not used or knew was possible, eg. Macros & if functions.

Thank you Len.

I am studying them now, they are something new to my self too.

Talk later

Tom
 
Last edited:
Question to the "UPDATE"

Hi,

I noticed that there is still some current running through the rows and maybe the columns so I increased the inline resistors from 1K0 to 2K0 and still see real faint flicker when leds are not supposed to be on.

Anyone know what may be a solution to this? You may have to watch ((((MY VIDEO)))) from post #25 to understand.

PS. attachment below of the schematic below.
 

Attachments

  • crossbar.JPG
    crossbar.JPG
    66.9 KB · Views: 141
Last edited:
Anyone know what may be a solution to this?
Try adding a respective resistor (say 10 x the base resistor value) between base and emitter of each transistor, to ensure turn-off.
 
Try adding a respective resistor (say 10 x the base resistor value) between base and emitter of each transistor, to ensure turn-off.

That should not be necessary since the PIC outputs switch between V+ & Gnd.

I study your circuit further & post later.
 
This is how I would do it.

Remove resistors R15~18.
Insert resistors in series with the emitters as in the diagram.
Change the base resistors to 3k3.

This arrangement not only saves on the number of resistors, but it provides a reverse bias to the transistors that are supposed to be off.

EDIT.
I just did what I should have done intitially - calculate the voltages & currents.

I have replaced the previous diagram with a new one & added the drawing that I did to do the calculations. (Drawn for the situation during one scan period)

However, I really think your problem is in the software. I think there may be an overlap period where the next transistor is turned on (then a short delay) before the previous is turned off.

But try the hardware mod first as it saves on resistors anyway.

If it proves to be in the software, I have a suggestion as to how you can fix it.
 
Last edited:
EDIT.
I just did what I should have done initially(spell checked) - calculate the voltages & currents.

I have replaced the previous diagram with a new one & added the drawing that I did to do the calculations. (Drawn for the situation during one scan period)

However, I really think your problem is in the software. I think there may be an overlap period where the next transistor is turned on (then a short delay) before the previous is turned off.

But try the hardware mod first as it saves on resistors anyway.

If it proves to be in the software, I have a suggestion as to how you can fix it.

I think your calculations are true. I remember something about pnp and npn switches drop 0.7 volts when turned on.

I'm gonna try to get this into the proto-board and see if it clears up the problem. Then next will be to proof read the software.

Thank you Len and Thank you alec_t for the responses.
 
Last edited:
Tom,
It occurred to me, while having lunch, that your problem could be due to the transistor storage time since you are over driving the transistors.

Yes, the base/emitter voltage of bipolar transistors is in the region of 0.6 ~ 0.9 Volt depending upon the collector current.

The collector current in bipolar transistors is determined by the charge in the base/emitter region. This is a function of the base/emitter voltage. Thus the collector current is an exponential function of the base/emitter voltage.

When the transistor goes into saturation, there is an excess of charge in the base/emitter region.

This means that when the voltage driving the base current is switched to zero, the collector current does not fall to zero immediately because the base/emitter charge maintains the collector current until it decays to the point where the collector current is no longer sustained.

I have attached the results of the simulation I did of your circuit. I only included the NPN side since the PNP side will be similar. The simulation shows that the storage time is about 2 us.

This time seems too short to be a problem, but perhaps not. Of course, any software delays will add to this time.

In my next post, I'll attach the simulation of the circuit modified as I suggested.
 
Last edited:
Here is the simulation of the modified circuit.

Note that the storage time is now about 0.75 μs because of the reverse bias across the base/emitter junction when the driving voltage V2 goes to zero and the because there is less charge then the base emitter region. In the previous post, the base/emitter voltage was 0.83 V whereas it is 0.75 V in this case, compare the third attachment in each post.

Note that the base current is about the same as before (-0.7 mA) because the base resistor is 3.3 times greater.

The base voltage is approximately 2.4 V while the transistor is on, so the current that is causing the base charge to decay is -2.4/3.3 = -0.7 mA. (it is negative since the current is coming out of the base).
 
Last edited:
Here is another option.

It has 2 advantages

The LEDs are reverse biassed when off.
The LED that is on has the sum of the collector & base currents (ie. the emitter current) through it.

However, you need to change the .asm in order to invert the PIC outputs since RB3:0 must now be Active Low & RB7:4 must be Active High.

Note that the storage time is about 0.2μs.
 
Delay in construction

I am still in the process of setting up my new Electronics ManCave. Moved to new home. Will be back soon.

Tom
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top