Shop OBEX P1 Docs P2 Docs Learn Events
ADC problems.... — Parallax Forums

ADC problems....

TristonazTristonaz Posts: 4
edited 2007-04-11 03:10 in General Discussion
Hello,

I'm in a microcontroller class and my instructor has agreed to let me use the SX instead of the pic kits here. For my first project i am supposed to modify the ADC program on page 302 of "Programming the SX Microcontroller". The idea is to modify it so that instead of controlling the PWM , port B will be used to output an eight bit binary number to some LED's. The binary number will be higher for greater voltages and smaller for lower voltages. Now I've been playing around with this program for awhile now and no matter what i do I can't get the LED's to reflect the voltage at the output. The Code is commented below, so It should be relatively easy to follow (I hope). i believe it to be a logical error, but I'm still really new to the sx assembly language.

I thank you for any help you can give me.

Triston


*********************Code******************************
include "Setup28.inc"
Reset main

TRIS equ $0f
LVL equ $0d
PWMpin equ rb.6 ;Port pin for PWM output

IntPer equ 163

org $08
PWMAcc ds 1 ;Counter for PWM

org 50h ;Bank 2 variables
analog equ $ ;ADC bank
port_buff ds 1
adc0 ds 1 ;ADC0 Value
adc0_acc ds 1 ;ADC0 Accumulator gb
adc0_count ds 1 ;Time Counter

org $000
bank analog ;select ADC bank

;**Virtual peripheal for two A/D Converters *************************
;
adc
mov w, >>rc ;Read Current state of ADC's
not w ;turn inputs to outputs
and port_buff,w ;Save new value in buffer
mov rc,port_buff ;Refresh charge Discharge lines

sb port_buff.4 ;ADC0 above threshold ?
incsz adc0_acc ;if so, increment accumulator
inc adc0_acc ; and avoid overflow by skipping
dec adc0_acc ; the second inc instruction



inc adc0_count ; increment the counter
jnz :done_adcs ; Continue if not yet done
mov adc0, adc0_acc ;Update ADC0 value
clr adc0_acc ;Clear ADC0 accumulator

:done_adcs



mov w, #-IntPer ; Call ISR every 'IntPer' cycles
retiw

org $100
;** The Main program ***********************************************
main
clr rc ;intialize Port C
mov !rc, #%10101111 ;Configure Port C I/O pins
mov !rb, #%00000000 ;Configure Port B output for LED
mode LVL ;Set port C input to CMOS
mov !rc,#0 ; CMOS
mode TRIS ;Restore MODE direction

include "Clr2x.inc" ;Clear all data memory

mov !option,#%10011111 ;Enable RTCC interrupt

:loop
bank analog
mov w,adc0
mov rb,w
jmp :loop

Comments

  • PJMontyPJMonty Posts: 983
    edited 2007-04-10 23:06
    Triston,

    Before anyone jumps in to help, I am curious to know if you tested the unmodified program that controls PWM and verified that it works on your setup. By "verified," I mean that you ran the program, input different voltages to the circuit, and saw the expected results on the output.

    It's important in these situations to make sure you have a baseline to compare to before jumping in and modifying things.

    Thanks,
    PeterM
  • TristonazTristonaz Posts: 4
    edited 2007-04-11 03:10
    yes, I did test the unmodified program and it did not work as expected. However, I did establish that the PWM program worked, because I manually modified the adc0. I was unable to verify the ADC VP though..... When the ADC ran the ADC0 and the ADC1 always read FF, and it was my understanding that this value would change in responce to the voltage on the ADC input.
Sign In or Register to comment.