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.

Pic16f818

Status
Not open for further replies.
Interrupt

It doesn't ring any bell but sets a flag! :p
 
So the word interrupt is the key! Thanks atferrari therefore I see there is no use to say goto interrupt or org 0x4.

Thanks again
 
So the word interrupt is the key! Thanks atferrari therefore I see there is no use to say goto interrupt or org 0x4.

Thanks again

hi Hesham,
I explained days ago how the PIC generates an Interrupt.

You write the appropriate bits into the Control registers for the Internal PIC peripheral that you want to generate the Interrupt.
So when the condition within the peripheral is met, IT generates the Interrupt.

If you wanted say Timer 1 to generate an interrupt on Overflow you would set the correct bits in the Timer 1 Control registers.
 
So when the program start running the Timer 1 will run independant from the program right?

Then, When an overflow happen say after 2ms for an On time the timer start again from begining and another overflow happen say after 18ms for an Off time the timer start again and again right?

This is the way it works Right?

Thanks in advance
 
So when the program start running the Timer 1 will run independant from the program right?

Then, When an overflow happen say after 2ms for an On time the timer start again from begining and another overflow happen say after 18ms for an Off time the timer start again and again right?

This is the way it works Right?

Thanks in advance

hi,
Its ALL in the 818 datasheet.:)
See Page 19 and Page 62.
 

Attachments

  • esp03 Nov. 19.gif
    esp03 Nov. 19.gif
    25.7 KB · Views: 167
If you read the data sheet and specifically the PWM section, you will find an explanation of the special event trigger(SET). When the PWM module is setup to use the SET, the CCP1L/H registers effectively become the time period for timer 1. Whatever value is written to CCP1L/H will be the value that timer 1 resets at and also causes an interrupt. Study the code and see how that happens.

Also, read the data sheet and try to figure out what the (my) code is actually doing rather than just keep asking newby questions here. You have been a member here for over 9 months and you are still asking basic questions.

Mike.
 
Ya, Reading and asking newby questions are improper thing to do I totally agree.

Maybe I keep asking dumpy questions because I think its hard one but when you answer them it appear to be easy.

I will try my best googling before asking any new newby question.

I think knowing how to activate a timer using MPLAB to see the REAL TIME of a program is an essential thing to learn so you can test your code prior programming and using function generator.

Q1> How can i activate the timer in simulation in MPLAB assembly? If this is a simple question ignore it :( if you think it will help many people answer it :)
 
Last edited:
Forget Simulator I will do real time checking :)

I just wanted to make sure my servo circuit is correct BTW i am using Pommie codes for the PIC16F877 :)

It's not working when i connect everything just wanted to make sure the circuit is the problem or the codes?
 

Attachments

  • 16F877 + servo.JPG
    16F877 + servo.JPG
    63 KB · Views: 441
Forget Simulator I will do real time checking :)

I just wanted to make sure my servo circuit is correct BTW i am using Pommie codes for the PIC16F877 :)

It's not working when i connect everything just wanted to make sure the circuit is the problem or the codes?

hi,
Goto Oshon Software Homepage and download the free trial of the PIC SIM IDE.

Please post your FULL code.:) and the complete circuit.
 
Last edited:
The codes is working fine I just simulate it :)
I added a break point before the interrupt and read the timming it's sweet to do simulation.
Code:
;*******************************************************************
;                           16F877 PWM Program
;*******************************************************************

		include	"p16f877.inc"

		errorlevel	-302
		radix	dec

	__CONFIG _CP_OFF & _DEBUG_ON & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _LVP_OFF & _CPD_OFF

		cblock	20h
OnTime:2
OffTime:2
		endc

		cblock	71h
int_work
int_status 
int_pclath
		endc

		org     0h
		nop
		goto    start
		nop
		nop
		
		org 	04h
interrupt	movwf	int_work
		swapf	STATUS,W
		movwf	int_status
		bcf	STATUS,RP0
		bcf	STATUS,RP1
		movfw	PCLATH
		movwf	int_pclath
		clrf	PCLATH

		btfsc	PORTB,0
		goto	TurnOff
; turn on the output and write the on time
		nop;		delay to make both path identical
		bsf	PORTB,0;<<<<<<<<<< Break Point
		movfw	OnTime+1
		movwf	CCPR1H
		movfw	OnTime
		movwf	CCPR1L
		goto	DonePWM

TurnOff		bcf	PORTB,0;<<<<<<<<<< Break Point
		movfw	OffTime+1
		movwf	CCPR1H
		movfw	OffTime
		movwf	CCPR1L
DonePWM
		bcf	PIR1,CCP1IF;	reset special event trigger interupt

		movfw	int_pclath
		movwf	PCLATH
		swapf	int_status,W
		movwf	STATUS
		swapf	int_work,F;	swap to file
		swapf	int_work,W;	swap to work
		retfie


start		bsf	STATUS,RP0
		bcf	STATUS,RP1
		bsf	STATUS,IRP;	all indirest access is to 100h - 1ffh
		 movlw	(0<<NOT_RBPU|0<<INTEDG|0<<T0CS|0<<T0SE|0<<PSA|B'000'<<PS0)
		movwf	OPTION_REG
		movlw	b'11111110'
		movwf	TRISB
		bcf	STATUS,RP0
		movlw	(b'01'<<T1CKPS0|0<<T1OSCEN|0<<NOT_T1SYNC|0<<TMR1CS|1<<TMR1ON)
		movwf	T1CON;		enable timer 1
		movlw	low(5000)
		movwf	CCPR1L
		movwf	OnTime
		movlw	high(5000)
		movwf	CCPR1H
		movwf	OnTime+1
		movlw	low(45000)
		movwf	OffTime
		movlw	high(45000)
		movwf	OffTime+1
		movlw	(0<<CCP1X|0<<CCP1Y|b'1011'<<CCP1M0);	enable special event trigger on CCP1
		movwf	CCP1CON;	
		bsf	STATUS,RP0
		bsf	PIE1,CCP1IE;	enable CCP1 interupt
		bcf	STATUS,RP0

		movlw	(1<<GIE|1<<PEIE|0<<T0IE|0<<INTE|0<<RBIE|0<<T0IF|0<<INTF|0<<RBIF)
		movwf	INTCON;		enable Peripheral interupts

Loop		
		goto	Loop


		END
That is the complete circuit did i miss anything in it?

Thanks in advance
 
That is the complete circuit did i miss anything in it?

How is the servo motor connected to the PIC circuit.?

The program produces a pulse Ok, on PORTB.0 when run in the Oshonsoft.
 
I have a servo motor ds8911 which need a voltage between 4.8-7.4V. I am using 5V from the same power supply to the PIC and the servo and also I am using same ground as for the PIC and as for the servo. The control wire of the servo is connected to RB0.

Here is the diagram

Thanks in advance

hi,
I have already seen that diagram.

How is the servo motor connected to the PIC pin, is the PIC capable of driving that servo directly or will it require a transistor driver.?

EDIT:
attached a spec for the motor NOTE the drive current.!!!
 

Attachments

  • esp03 Nov. 20.gif
    esp03 Nov. 20.gif
    30.7 KB · Views: 195
Last edited:
Directly i connected it.

Ok I Read that 2750mA but the control wire is from the PIC. Does the control wire need to stand that much?

I am not using any transistor if you think it is necessary please let me know.
 
Last edited:
Directly i connected it.

Ok I Read that 2750mA but the control wire is from the PIC. Does the control wire need to stand that much?

I am not using any transistor if you think it is necessary please let me know.

hi,
The Control wire is most likely a TTL voltage level, I cannot see any reference in the spec sheet.

I was concerned that you may have been trying to connect the motor directly to the PIC.!

If possible, its a good idea to have a separate power supply to the motor, it can draw over 2.7Amps from the 5V line.
What is the voltage source for the project.?
 
Right now I am using 5V power supply of our LAB it can handle heavy current like 20A in the future I am thinking about using small AA size batteries connect many in parrallel.

The servo motor is not connect to anything right now I am doing a free test.

Can some one comment on my previous post servo motor diagram why it's not working?

I already connected an Oscilloscope to RB0 and tried reading the generated pulse nothing was showing>< Any Ideas?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top