DECFSZ [NOT AN] issue on the PIC 16F1509 ?

EDIT: I hate going to the message board… naturally I am licking my wounds from getting scolded for daring to use cblock…

GPR_VAR UDATA

var_name  RES 1

…. took care of this issue… at least that fiasco is over.. and I thought the PWM was going to be the hard part!  /EDIT

This code is killing me. I’ve pulled it out of something I’m working on… it has been kicking my ass for two days now.

The LED on PORTC,2 should be pulses for a few hundred nanoseconds and then go off….. right?  No.. the decfsz sits in an endless loop it seems. Why? I’ve messed up somewhere here?

 

  errorlevel -230, -302, -303, -313
    LIST R=DEC

#include "p16f1509.inc"


    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _CLKOUTEN_OFF
    __CONFIG _CONFIG2, _LVP_OFF & _STVREN_ON


cblock
    int_delay1
    int_delay2
endc

RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    START                   ; go to beginning of program


MAIN_PROG CODE                      ; let linker place main program


INIT:
                            ;RC5 = PWM1
    BANKSEL LATA            ;Data Latch
    CLRF LATA               ;
    BANKSEL ANSELC          ;
    CLRF ANSELC             ;Digital IO
    BANKSEL PORTC           ;
    BCF PORTC,5             ;Clear PWM1
    BANKSEL TRISC           ;Set all PORTC to outputs
    CLRF TRISC

    BANKSEL OSCCON
    MOVLW   0x78            ;16MHZ Clock
    MOVWF   OSCCON

    RETURN


START
    CALL    INIT

           BANKSEL int_delay1
            MOVLW   0x01
            MOVWF   int_delay1
            BSF PORTC,2
OLOOP
            NOP
            BANKSEL int_delay1
            DECFSZ int_delay1,1
            GOTO OLOOP
            BCF PORTC,2



    NOP

LOOP:
    NOP
    GOTO LOOP                ;loop forever

    END

PWM on the PIC16F1509 in ASM

[Edit: If you’re looking for NCO (numerically controlled oscillator) usage instead of the PWM module take a look here instead. However note the code is in C (for XC8) not ASM]

Another lazy Sunday… A lot of OT the last few weeks at work and Sunday about the only day I have for relaxation so to clear my mind I wrote some test code for Pulse Width Modulation on a development board I purchased from @TINDE made by @TAUTIC . I’ll attach the code for anyone to use.

MPLAB on the laptop with a @TAUTIC / @TINDE dev board with a PWM test output.
MPLAB on the laptop with a @TAUTIC / @TINDE dev board with a PWM test output.

The code outputs on PWM1 (RC5) at about 1Khz at just under 50% duty cycle but that easy to change if you read the Microchip 16F1508/9 spec sheet section 23.

;*******************************************************************************
;                                                                              *
;    Microchip licenses this software to you solely for use with Microchip     *
;    products. The software is owned by Microchip and/or its licensors, and is *
;    protected under applicable copyright laws.  All rights reserved.          *
;                                                                              *
;    This software and any accompanying information is for suggestion only.    *
;    It shall not be deemed to modify Microchip?s standard warranty for its    *
;    products.  It is your responsibility to ensure that this software meets   *
;    your requirements.                                                        *
;                                                                              *
;    SOFTWARE IS PROVIDED "AS IS".  MICROCHIP AND ITS LICENSORS EXPRESSLY      *
;    DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING  *
;    BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS    *
;    FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL          *
;    MICROCHIP OR ITS LICENSORS BE LIABLE FOR ANY INCIDENTAL, SPECIAL,         *
;    INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, HARM TO     *
;    YOUR EQUIPMENT, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR    *
;    SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY   *
;    DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER      *
;    SIMILAR COSTS.                                                            *
;                                                                              *
;    To the fullest extend allowed by law, Microchip and its licensors         *
;    liability shall not exceed the amount of fee, if any, that you have paid  *
;    directly to Microchip to use this software.                               *
;                                                                              *
;    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF    *
;    THESE TERMS.                                                              *
;                                                                              *
;*******************************************************************************
;                                                                              *
;    Filename:      main.asm                                                   *
;    Date:          Sept 29 2013                                               *
;    File Version:  1.0                                                        *
;    Author:        Charles Douvier                                            *
;    Company:                                                                  *
;    Description:   Test of PWM1                                               *
;
;    Device 16F1509
;
;
;
;
; PIN DIAGRAM
;
;   RA0                             RC0
;   RA1                             RC1
;   RA2                             RC2     STATUS LED
;                                   RC3
;   RA4             RB4             RC4
;   RA5             RB5             RC5     PWM1
;                   RB6             RC6
;                   RB7             RC7
;
;------------------------------------------------------------           *
;*******************************************************************************
;                                                                              *
;    Notes: In the MPLAB X Help, refer to the MPASM Assembler documentation    *
;    for information on assembly instructions.                                 *
;                                                                              *
;*******************************************************************************
;                                                                              *
;    Known Issues: This template is designed for relocatable code.  As such,   *
;    build errors such as "Directive only allowed when generating an object    *
;    file" will result when the 'Build in Absolute Mode' checkbox is selected  *
;    in the project properties.  Designing code in absolute mode is            *
;    antiquated - use relocatable mode.                                        *
;                                                                              *
;*******************************************************************************
;                                                                              *
;    Revision History:
;           2013-09-28  Initial                                                *
;                                                                              *
;*******************************************************************************

;*******************************************************************************
; Processor Inclusion
;
;*******************************************************************************
    errorlevel -230, -302, -303, -313
    LIST R=DEC
#include "p16f1509.inc"
;*******************************************************************************
;
; Word Setup
;
;
;*******************************************************************************
    __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _CLKOUTEN_OFF
    __CONFIG _CONFIG2, _LVP_OFF & _STVREN_ON
;*******************************************************************************
;
;  Variable Definitions
;
;*******************************************************************************
; TODO PLACE VARIABLE DEFINITIONS GO HERE
;*******************************************************************************
; Reset Vector
;*******************************************************************************
RES_VECT  CODE    0x0000            ; processor reset vector
    GOTO    START                   ; go to beginning of program
;*******************************************************************************
; TODO INSERT ISR HERE
;*******************************************************************************
; MAIN PROGRAM
;*******************************************************************************
MAIN_PROG CODE                      ; let linker place main program
INIT:
                            ;RC5 = PWM1
    BANKSEL LATA            ;Data Latch
    CLRF LATA               ;
    BANKSEL ANSELC          ;
    CLRF ANSELC             ;Digital IO
    BANKSEL PORTC           ;
    BCF PORTC,5             ;Clear PWM1
    BANKSEL TRISC           ;Set all PORTC to outputs
    CLRF TRISC
    BANKSEL PORTC
    BSF PORTC,2
    BANKSEL OSCCON
    MOVLW   0x78            ;16MHZ Clock
    MOVWF   OSCCON
    BANKSEL PWM1CON         ;
    CLRF PWM1CON            ;Disable PWM bits
    BANKSEL PR2
    MOVLW 0xFF
    MOVWF PR2               ;Load PR2 with 0xFF
                            ;Timer/PR set up is 973Hz
    BANKSEL PWM1DCH
    CLRF PWM1DCH
    BANKSEL PWM1DCL
    CLRF PWM1DCL
    BSF PORTC,2
    BANKSEL PWM1DCH
    MOVLW   0x6F
    MOVWF   PWM1DCH

                            ;copied code, havent check this yet.
    ;ENABLE INTERRUPT
    BANKSEL PIE1
    BSF PIE1,1
    bcf        PIR1,2
                    ;-----------------------------------
                    ;Configure and start Timer2
;CONFIGURE TIMER.. copied code review.
    BANKSEL T2CON
    MOVLW B'00000110'   ;MOVLW B'00000110'
    MOVWF T2CON
                    ;Enable PWM output pin and wait until Timer2
                    ;overflows, TMR2IF bit of the PIR1 register is set.
                    ;See note below.
    btfss    PIR1,1                ;Test for T2 interrupt
    goto    $-1
                    ;Enable the PWMx pin output driver(s) by clearing
                    ;the associated TRIS bit(s) and setting the
                    ;PWMxOE bit of the PWMxCON register.
                    ;Configure the PWM module by loading the
                    ;PWMxCON register with the appropriate values.
    BANKSEL TRISC          ;Enable Outputs
    CLRF    TRISC
    BANKSEL PWM1CON        ;Enable PWM1
    MOVLW    B'11000000'
    MOVWF    PWM1CON
    RETURN
START
    CALL INIT
    BANKSEL PORTC            ;select PORTC for heatbeat
LOOP:
    BSF PORTC,2              ;heart beat
    MOVLW 0x55
    NOP                      ;future code
    BCF PORTC,2
    GOTO LOOP                ;loop forever
    END

 

 

Using a stepper motor as a rotary encoder

I won’t ruin the surprise on what I’m working on. No laser printer, or CNC machine for me (for now?). I borrowed the concept of using a stepper motor from this: website link.  I used a LM339 for my comparator because that’s what I had, it worked fine. I have some more testing but I’m pretty sure my low resistance coils on the stepper cause my direction accuracy to be wrong as single stepping about 20% of the time. At a slow speed it works fine. I’ll test my theory out this weekend sometime. Also shown on that 44 pin vector board as I mentioned is a SR flip-flop and some logic to latch the direction and accept a reset from a MCU once the state it read. I didn’t want to deal with any clocks. I realize I could have put that all in software but I didn’t feel like it and I have a lot of vector board to fill up 🙂   The back end of the circuit can be found on the second photo. I had put a OR gate in my written schematic to automatically reset the SR (74LS279) but I dropped it in prototyping. I just got my stepper driver for the NEMA23 stepper mounted there so that’ll make a “fun” Friday night tomorrow as it’s suppose to be rainy and a little chilly out…

Another Work-In-Progress shot.. I just got my stepper driver from eBay today shown to the left. Tomorrow I'll test it out and write some code for the encoder.
Another Work-In-Progress shot.. I just got my stepper driver from eBay today shown to the left. Tomorrow I’ll test it out and write some code for the encoder.
A stepper motor encoder with directional latch (SR Flip-Flip with MCU reset) This works okay with some minimum rotation. Single stepping isn't the best but it's likely because of the low resistance coils.
A stepper motor encoder with directional latch (SR Flip-Flip with MCU reset) This works okay with some minimum rotation. Single stepping isn’t the best but it’s likely because of the low resistance coils.

Doubts about the IGBT isolated drive voltage

Fresh out of repair I hooked up my IGBT pack for testing one channel. I had vaporized some traces off the secondary supply voltage. I hooked up the load, the low voltage drive and then my best guess on the isolated power supply. I guessed wrong. I was hoping because the Chiller had a good 4 or 5 24VAC secondary transformers and 24VAC is ubiquitous throughout the HVAC world. I guessed wrong. I let some more smoke out.

I am lucky I have a new friend who works on Chillers. He hooked me up with the water-cooled heat sink and I have a pump and some capacitors coming to me as well. I’m going to ask him to let me poke into an operating board with my multimeter next time we are working together to find out whats going on. The pair of wires is feeding 6 isolation transformers in parallel with what I thought were MOVs but it’s hard to tell, no markings and I doubt my soldering skills could get them safely off and back on again? Maybe…

Well back to the drawing board… rumor has it they might have another (smaller) drive out of a refurbished unit…. could I be so lucky?

IGBT pack married to it's heat sink
IGBT pack married to it’s heat sink

Western Electric VOM

A brief glimpse into the start of my weekend: I pulled a Western Electric VOM out of my stash of “stuff to check out sometime”. This comes from stuff bought in HAM auctions found in boxes of random stuff amateurs tend to collect and pass on. I had hopes of getting this VOM serviceable as I don’t have one of those iconic Simpson 260s. I find the scaling very interesting … I immediately ran into a D cell that could’ve done a lot more damaged as it was a long dried up mess of corrosion. Then the 30 volt battery. Well I can’t see modifying this classic to fit some 9volts … So I’ll clean this up and it’ll find it’s way to a shelf for permanent display. That’s too bad; maybe I’ll run into a cheap 260 one of these days.

Also on my to-do list is building a small magnetometer to test and see if I have further interest in building a larger unit and then perhaps find a way to build of buy a monochrome to HDMI or VGA adapter for my XT.

I’ve abandoned my portable “weather” station. I found that I likely won’t carry it with me as I ditched a lot of novel items I had at basecamp over my last backpacking trip. I probably hauled 30 lbs to basecamp for a 5 day trip… Used maybe 20 lbs of it. So I’ll be retiring the sensors and repurposing the Bluetooth and MCU development boards.

20130914-141035.jpg

Western Electric Volt-Ohm Meter

20130914-141047.jpg

Internal view that includes the 30 volt battery and the start of the coil for a magnetometer on the left.