If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
For starters, There is NO 16 bit compare register for PWM use. The upper byte is shared with a few other bits of config. There is ONLY 10 bit's available for PWM use in hardware. Read the data sheet for the processor you are using.
Dave Purola,
N8NTA
EN82fn
Thanx Dave,
I use 10 bit hardware PWM. But I need more resulation. I such a little trick
Talat
What Acetronics2 is trying to say is, when accessing PBP variables inside of an ASM routine you need to prefix an underscore before the variable name such as "movf _PWM_VAL,W ; lb"
As far as getting more resolution from the PIC processor, Your out of luck. You can always build your own digital pwm circuit with hardware if you are so inclined.
Last edited by Dave; - 22nd August 2014 at 11:55.
Dave Purola,
N8NTA
EN82fn
Hi Dave,
This is just copy-paste error..
What's interesting is that, these codes do not work to as 8-bit (10 bit too)
Thanx
Hi,
So, Microchip themselves and previous posters in the this thread (Darrel, Bruce, Norm) are wrong then, what am I missing?As far as getting more resolution from the PIC processor, Your out of luck.
When using the CCP module in PWM mode it's limited to 10bits resolution. But if you use it in compare mode, the way that the application note describes you can get 16bit resolution but:
1) You won't be able to get 100% dutycycle
2) The maximum output frequency will be limited to ~122Hz @32MHz.
3) You'll get some CPU load from the interrupt processing.
4) You need to deal with assembly code in the ISR (or deal with more "CPU load" if using DT-Ints)
/Henrik.
But Darrel did not do this in his code, prefix with "_". Also as Talat has said he is following Darel's example for "16 bit PWM using CCP1" which obviously worked for Darrel, Bruce and Norm.
So Talat 16 bit PWM is possible. I have read the whole thread and the datasheets for the 18F452 and the chip you are using 16F1827.
The first possible issue Darell said his code was for 18F's only in post 3 does anyone know why not 16F's? The 16F has CCPx compare mode.
With regard to the 16F1827 I think CCP4 has the required features needed and CCP1 does not but I need more time to re-read the datasheet but in the meantime it would be helpful if some one could confirm which CCPx should be used.
Steve Earl www.datageo.co.uk
A pbp version
Code:'**************************************************************** '* Name : PWM16.BAS * '* Author : RICHARD * '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 8/23/2014 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** #CONFIG __config _CONFIG1, _FOSC_INTOSC & _CP_OFF & _WDTE_ON & _PWRTE_ON & _MCLRE_ON & _CLKOUTEN_OFF __config _CONFIG2, _PLLEN_ON & _LVP_OFF #ENDCONFIG include "dt_ints-14.bas" asm INT_LIST macro INT_HANDLER TMR1_INT, _Tm1, asm,yes endm INT_CREATE ENDASM DEFINE OSC 32 sSEROUT_PIN VAR PORTA.0 sBAUD CON 84 '16416 = 19200 BAUD yTEMP VAR Byte wDUTY VAR WORD '*********************************************** START: ' disable analog functions OSCCON=$70 ANSELA=0 ANSELC=0 '******************** '16 BIT CCP1 PWM T1CON = 0 ' Turn off Timer1 with a Prescaler value of 1:8 PIE1 = %00000001 ' enable TMR1 overflow interrupt INTCON = %11000000 ' enable global and peripheral interrupts ' LOW PORTC.2 ON MATCH TM1 WITH DUTY ccp4con=0 wDUTY = 32768 ' 32768 = 50% DUTY PWM T1CON.0 = 1 ' TMR1 ON CCPR4H=$80; CCPR4L=0; PAUSE 800 SerOut2 sSEROUT_PIN,sBAUD,["START",13] trisc = %11111001 '*********************************************** CCP4CON = %00001001 MAIN: yTEMP = yTEMP +1 SerOut2 sSEROUT_PIN,sBAUD,["LOOP ",Dec yTEMP,13] PAUSE 500 Goto MAIN '**** ASSEMBLY INTERRUPT ROUTINE **** Tm1: Asm bsf PORTC ,2 CHK?RP CCP4CON clrf CCP4CON movlw 9 movwf CCP4CON banksel 0 bcf PORTC ,2 EndAsm '**** END ASSEMBLY INTURRUPT ROUTINE **** @ INT_RETURN End
Bookmarks