Hi Everyone, and many thanks for the answers to my post!!!

Hi follow your opinions and i change the code to this;

Code:

'****************************************************************
'* Name : PWM.BAS *
'* Author : Gadelhas *
'* Notice : Copyright (c) 2010 *
'* : All Rights Reserved *
'* Date : 28-11-2010 *
'* Version : 1.0 *
'* Notes : *
'* : PIC12F683 + MICROCODE + EASYPICV6 *
'****************************************************************
' INCLUDE's e FUSES
' ====================================================================
@ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BOD_OFF
' ====================================================================
Define OSC 8
' VARIÁVEIS
' ====================================================================
AdcValue var word: AdcValue=0
I var word: I=0
Sample var word: sample=0
' REGISTOS E PINOUT 1 = IN; 0 = OUT
' ====================================================================
'76543210
TRISIO = %00000001
'76543210
GPIO = %00000000
ANSEL = 1 'GP0 AANALOG
VRCON = 0 'VREF OFF
CMCON0 = 7 'COMPARATOR OFF
ADCON0 = %10000000 'RIGHT JUSTIFY - 128
PR2 = %00011000 'SET 24 - 5000Hz - 8Bits
T2CON = %00000110 'TIMER2 ON - PRESCALER 1:16 - Max Duty Value 100 - 1% Step
CCPR1L = %00000000
CCP1CON = %00001100 'PWM ON
' NOMES PINOUT
' ====================================================================
POT1 VAR GPIO.0
' DEFINIÇÕES
' ====================================================================
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
' INICIO PROGRAMA
' ====================================================================
Main:
gosub ADC
CCPR1L.7=AdcValue.9
CCPR1L.6=AdcValue.8
CCPR1L.5=AdcValue.7
CCPR1L.4=AdcValue.6
CCPR1L.3=AdcValue.5
CCPR1L.2=AdcValue.4
CCPR1L.1=AdcValue.3
CCPR1L.0=AdcValue.2
CCP1CON.5=AdcValue.1
CCP1CON.4=AdcValue.0
GOTO MAIN
' SUB-ROTINAS
' ====================================================================
ADC:
for I = 1 to 15
ADCON0.1 = 1
Not_Done:
if ADCON0.1 = 1 then not_done
adcin 0,AdcValue
sample = AdcValue + sample
next I
AdcValue = (sample/163)
sample=0
return
END

The code works great. Initially it had 288 words, after change went to 213 words.

Is it possible to improve this piece of code?;

Code:

CCPR1L.7=AdcValue.9
CCPR1L.6=AdcValue.8
CCPR1L.5=AdcValue.7
CCPR1L.4=AdcValue.6
CCPR1L.3=AdcValue.5
CCPR1L.2=AdcValue.4
CCPR1L.1=AdcValue.3
CCPR1L.0=AdcValue.2
CCP1CON.5=AdcValue.1
CCP1CON.4=AdcValue.0

Is this correct?

>>1 is the same as devide by 2

>>2 is the same as devide by 4

>>3 is the same as devide by 8

>>4 is the same as devide by 16

>>5 is the same as devide by 32

>>6 is the same as devide by 64

>>7 is the same as devide by 128

>>8 is the same as devide by 256

and

<<1 is the same as multiply by 2

<<2 is the same as multiply by 4

<<3 is the same as multiply by 8

<<4 is the same as multiply by 16

<<5 is the same as multiply by 32

<<6 is the same as multiply by 64

<<7 is the same as multiply by 128

<<8 is the same as multiply by 256

Thanks once again to everyone!!

## Bookmarks