Hi everyone, once again!
Hi made this code for controlling a DC motor with a PIC12F683.
The PIC reads the ADC value, and then controls the duty of the PWM output.
Everything is working good, however, i like to know your opinion about the code.
Is it possible to make any improvement, or other change to put the code better?
Here is the code
ThanksCode:'**************************************************************** '* 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 ' VARIABLES ' =========================================================== Duty var WORD: DUTY=0 AdcValue var word: AdcValue=0 I var word: I=0 Sample var word: sample=0 ' REGISTERS & PINOUT 1 = IN; 0 = OUT ' ==================================================================== '76543210 TRISIO = %00000001 '76543210 GPIO = %00000000 ANSEL = 1 VRCON = 0 CMCON0 = 7 ADCON0 = %10000000 ' PINOUT NAMES ' =========================================================== POT1 VAR GPIO.0 ' DEFINITIONS ' =========================================================== 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 ' MAIN PROGRAM ' =========================================================== Main: gosub ADC DUTY=(AdcValue*64)/256 HPWM 1, DUTY, 5000 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/15 sample=0 return END




Bookmarks