Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 11th October 2007, 07:00 AM   (permalink)
Default MPLAB simulating PWM on 16F628A

I have been poking around 16F84's for a while and have previously done pwm in software successfully, I am now experimenting with the 16F628A CCP module using MPLAB's MPLAB SIM simulator.
I have trawled the internet and have a fair idea of what it takes to get the CCP module running however after sometime (2 days) i cannot get MPLAB to show me the output from CCP1 on the logic analyzer.

Attached is the code i have been using.

Any hints would be greatly appreciated.



Thanks
Attached Files
File Type: txt Step01.txt (2.9 KB, 26 views)
Lost Tourist is offline  
Old 11th October 2007, 09:29 AM   (permalink)
Default

For some reason the simulator doesn't like the bottom 2 bits of CCP1CON being set.

You have a couple of mistakes, TMR2ON = bit 2 not 3, so you has a postscaler on timer2.
Your on time was longer than your period so it never toggled.

See below,

Mike.
Code:
init
		clrf	CCP1CON			; Clear CCP Control register to reset CCP module

		movlw	b'00101100'		; control word to switch CCP module to PWM mode (and period LSB's)
				; b:7-6 = not used
				; b:5-4 = LSB duty cycle
				; b:3-0 = CCP module configuration  11xx = PWM mode
		movwf	CCP1CON



		bsf		status,rp0	; access bank 1
		movlw	.25			; Set duty cycle
		movwf	PR2
		bcf		status,rp0	; return to bank 0

		movlw	.12			; set period of PWM
		movwf	CCPR1L
		bcf 	CCP1CON,5  ; set bit 1
   		bcf 	CCP1CON,4  ; set bit 0
		
		movlw 	b'00000110'   ; 		Turn on TMR2 and set post scaler to 1 and prescaler to 4
				; b:7 = not used
				; b:6-4 = post scale 0000 = 1:1
				; b:3 = 1 TMR2 ON
				; b:2-1= 10 prescale = 1:4
   		movwf 	T2CON

	
		retlw	0
Pommie is offline  
Old 12th October 2007, 07:13 AM   (permalink)
Default Thanks

Thanks for that Mike, everything is working properly now.

I currently have some small remaining issues with my circuit in that the frequency out of CCP1 is not exactly the predicted value but i think that's probably due to using the internal oscillator being temperature sensitive, either way i'm pretty sure i can work through that.

Thanks again.

David
Lost Tourist is offline  
Old 12th October 2007, 07:19 AM   (permalink)
Default

Set the prescaler to 1:1 and it will be much faster. About 4 times.

Mike.
Pommie is offline  
Old 12th October 2007, 09:32 AM   (permalink)
Default

BTW, your frequency will be 1,000,000/26/4 = 9615Hz. Is this what you are seeing. If you expect it to be 10KHz then change PR2 to 24.

It also makes no sense to have a prescaler of 4 on timer2. Change to a 1:1 prescaler, change the PR2 value from 25 to 100 and your PWM value will go from 0 to 400 instead of 0 to 100 (25 in CPR1L + 2 bits in CCP1CON).

Mike.
Pommie is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Question about Inchworm+ Quan Micro Controllers 54 28th October 2007 01:21 AM
Debugging 877A with MPLAB williB Micro Controllers 10 7th May 2007 04:53 PM
Need help badly on Inchworm and MPLAB thushy Micro Controllers 14 11th March 2007 07:05 PM
Some Question About Inchworm Ayne Micro Controllers 29 7th March 2007 04:08 AM
Inchworm project started williB Micro Controllers 69 5th March 2007 07:56 PM



All times are GMT. The time now is 09:59 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker