Revision: 1274 Author: robhamerling Date: Mon Aug 31 01:09:41 2009 Log: Simple dimmer with single channel PWM/ADC combination
http://code.google.com/p/jallib/source/detail?r=1274 Added: /trunk/sample/12F683_pwm_adc.jal ======================================= --- /dev/null +++ /trunk/sample/12F683_pwm_adc.jal Mon Aug 31 01:09:41 2009 @@ -0,0 +1,56 @@ +-- ------------------------------------------------------ +-- Title: Single channel dimmer +-- Author: Rob Hamerling, Copyright (c) 2009, all rights reserved. +-- Adapted-by: +-- Compiler: 2.4l +-- +-- This file is part of jallib (http://jallib.googlecode.com) +-- Released under the BSD license (http://www.opensource.org/licenses/bsd-license.php) +-- +-- Description: +-- This program shows a simple single channel dimmer by using +-- a combination of one ADC input pin and one PWM output pin. +-- Internal oscillator is used for minimum components. +-- PWM resolution of 256 steps is sufficient for this purpose, +-- and accorlingly low resolution ADC is selected. +-- +-- Sources: +-- +-- Notes: +-- +-- ------------------------------------------------------ +-- +include 12f683 -- target PIC + +-- Use internal oscillator at 8MHz +pragma target CLOCK 8_000_000 +pragma target OSC INTOSC_NOCLKOUT +pragma target WDT disabled +OSCCON_IRCF = 0b_111 -- Fosc = 8 MHz + +enable_digital_io() -- set all IO as digital + +-- ADC setup +const byte ADC_NVREF = 0 -- no external Vref +const ADC_RSOURCE = 4_700 -- Input resistance: 4.7K potmeter +const ADC_HIGH_RESOLUTION = FALSE -- Low res ADC is good enough! +include adc -- fetch the ADC librarye +adc_init() -- Initialize + +const byte ADC_CHANNEL = 3 -- potmeter connected to pin_AN3 + -- 12F683 has independent ADC channels +set_analog_pin(ADC_CHANNEL) -- init the selected ADC channel + +-- PWM setup ------- +include pwm_hardware -- fetch PWM library +pwm_max_resolution(1) -- max res. with highest possible freq. +pin_CCP1_direction = output -- set PWM-pin output + +var byte measure -- ADC value / PWM duty cycle + +-- ---- mainline ---- +forever loop + measure = adc_read_low_res(ADC_CHANNEL) -- get ADC result + pwm1_set_dutycycle(measure) -- copy to PWM duty cycle +end loop + --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jallib?hl=en -~----------~----~----~----~------~----~------~--~---
