Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Too many timers

Status
Not open for further replies.
Cool. That works. I get an error that portA is not previously defined. Is portA from a different type of pic? should we be using GPIO?
 
This is the code so far. It compiles with 1 error and says link step failed.
Also Error - section '.org_0' type is non-overlay and absolute but occurs in more than one input file.
I get the link step error whether I include the linker file or not.
Can anyone point out whats wrong please?
Code:
;//PREPROCESSOR ===============================================|---|

	LIST	p=12F683
	include "P12F683.INC"

    __CONFIG    _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
	errorlevel -302
	errorlevel -312

		EXTERN	adc
		EXTERN	EEPROMRW
		EXTERN	Interrupt_on_change

delA        equ 20h    ;
delB        equ 21h    ;
temp1        equ 22h    ;
temp2        equ    23h    ; 
pushes        equ    24h    
flashes        equ    25h
Stat_sav    equ 26h
W_sav       equ 27h
 
;****************************************************************
;Equates
;****************************************************************
status        equ    0x03
rp1            equ    0x06
rp0            equ    0x05
 
 
status        equ    03h
option_reg    equ 81h

    
        ;bits
 
rp0        equ    5            ;bit 5 of the status register
 
 
 
;****************************************************************
;Beginning of program
;****************************************************************
        org        0x00
	cblock 0x20
   		d1 
   		d2 
  		d3 
   		d4 
   		count1			; for 5 minute delay 	
		SW1				; Switch #1
		SW2				; Switch #2
		TMR				; timer value in minutes
  	endc 
        GOTO    SetUp
        nop
        ORG    4                ;interrupts always vector to here
        GOTO    isr
        nop
SetUp   bsf        status, rp0     ;Bank 1            
        movlw    b'10010100'        ;Set TRIS  GP0,1,5 out   GP2,4 input
        movwf    TRISIO               ;    
        bcf     option_reg,7    ;pull-ups enabled        
        MOVLW    b'00000100'        ;prescaler (1:32)
        movwf    option_reg     ;TMR0 interrupts = 6 mS apart
        BCF        STATUS, RP0        ;bank 0
        movlw   07h             ;turn off Comparator ports
        movwf   CMCON0           ;must be placed in bank 0  
        Clrf    TMR0            ;clear Timer0 register    
        clrf    flashes    
        incf    flashes
        movlw    0xA0            ;set GIE <7> and T0IE <5>
        movwf    INTCON            ;enable Interrupts
        goto     Main    
 
 
isr        MOVWF    W_sav            ;first save critical registers
        SWAPF    STATUS,W
        BCF        STATUS,RP0        ;change to bank 0 
        MOVWF     Stat_sav    
 
        btfss    GPIO,2        ;test switchA
        call    switchPressed
 
        BCF        INTCON,T0IF
        BCF        INTCON,INTF
        SWAPF    Stat_sav,W
        MOVWF    STATUS        ; restore status 
        SWAPF    W_sav,F    
        SWAPF     W_sav,W        ; restore w without changing status
        RETFIE    
 
;********************
;* Delays             *
;********************
 
 
_10mS    movlw    0Ah
        movwf    delB
        nop
        decfsz     delA,f
        goto     $-2
        decfsz     delB,f
        goto     $-4    
        retlw     00    
 
 
_250mS    nop
        decfsz     delA,f
        goto     $-2
        decfsz     delB,f
        goto     $-4    
        retlw     00            

; Delay = 300 seconds 
; Clock frequency = 4 MHz 
 
; Actual delay = 300 seconds = 300000000 cycles 
; Error = 0 % 
 

 
DelayW      movwf   count1 
 
Delay5
         ;299999995 cycles 
   movlw   0x54 
   movwf   d1 
   movlw   0xA1 
   movwf   d2 
   movlw   0xFD 
   movwf   d3 
   movlw   0x02 
   movwf   d4 
Delay_0 
   decfsz   d1, f 
   goto   $+2 
   decfsz   d2, f 
   goto   $+2 
   decfsz   d3, f 
   goto   $+2 
   decfsz   d4, f 
   goto   Delay_0 
 

      decfsz   count1   ,f 
      goto   Delay5 
      retlw   0x00
 
 
;****************************
;* Sub Routines             *
;****************************
 
switchPressed
 
        movf    flashes,W    
        movwf    temp1
        movlw   06
        xorwf   temp1     ;if flashes=6
        btfss   status,Z  ;z=1 if flashes=6
        goto    $+4
        movlw   1
        movwf   flashes
        goto    $-8        
 
        bsf     GPIO,0   ;turn on LED    
        call    _250mS
        bcf     GPIO,0   ;turn off LED    
        call    _250mS
        decfsz  temp1,f
        goto    $-5
        incf    flashes,f
        btfss   GPIO,2        ;loop until SwA is released
        goto    $-1
        retlw    00
 
 
;************************
;* Main                 *
;************************
 
Main    
   	 	btfss   GPIO,2        ;test switchA
    	call    SwA_Pressed
        btfss   GPIO,3        ;test switchB
        call    SwB_Pressed
        goto    $-4  
 
SwA_Pressed
		return
		goto Main

SwB_Pressed
		return
		goto Main

;************************
;*EEPROM                 *
;************************
 
        org        2100h            
 
 
        END
I have 3 more files added to the project with GLOBAL subroutines also. They are adc, EEPROMRW and Interrupt_on_change
 
Here is the program so far.
You can't use the switches to invoke sleep.
All that is left to include is the low-voltage detection.
 

Attachments

  • SimpleTimer.asm
    6.6 KB · Views: 106
Here is the program so far.
You can't use the switches to invoke sleep.
All that is left to include is the low-voltage detection.

You are a legend.
There is a whole lot of stuff there I may never understand but at least I learned something!
Thanks very much Colin. I had to alter a few things for the PIC12F683, just changing case in a lot of cases and defining delA and delB.
I received a few message 305's about EEADR saying using default destination of 1 which I am guessing is fine.
And warning 211 on this line
Code:
clrw	EEADR			;EEPROM location 0 for flashes of LED
saying extraneous arguments on line but I can't see too much wrong with it.

However it compiles fine.
I have written a little code for the adc
Code:
	CBLOCK	0x21
NumH
NumL
	ENDC
			
	
Init_ADC	org		0x004
; Set ADCON0
    		movlw   b'10001101'
    		movwf   ADCON0
			CALL SampleTime ;Acquisiton delay
; Set ADSEL
			BANKSEL ANSEL
    		MOVLW b'00011000' ;Fosc 8,an3
			MOVWF ANSEL ; and GP4 as analog
    		BANKSEL ADCON0
		return

Read_ADC
    		bsf	ADCON0, GO		;initiate conversion
    		btfsc   ADCON0, GO
    		goto    $-1			;wait for ADC to finish

    		movf    ADRESH,W
    		andlw   0x03
    		movwf   NumH
    		BANKSEL ADRESL
    		movf    ADRESL,W
    		BANKSEL	ADRESH
		movwf	NumL			;return result in NumL and NumH
		return    
SampleTime	nop
			nop
			nop
			nop
			nop
			nop
			nop
			nop
			nop
			nop
			nop
			nop
			return

But I need to learn how to mask some bits so I do not need to worry about 2 memory ADRES locations and round up to 1 number to compare.

I also am not too sure of the conversion at this stage
I think with 12v and 1 33k and a 10k resistor in the divider network then I have a ratio of .2325
12/43=.2325 so 10v*.2325 would be 2.325v at the pic and a value of 212.42 in ADRES.

However I need to read up a little more on that to be sure.
 
Last edited:
5v equals 1024 so division is 12mV and this is about 27mV when referenced to the 12v battery.

We are talking about cut-off voltage - not supply voltage. What is the cut-off voltage for the 12v battery.
 
Last edited:
incf EEADR,1

clrw EEADR should be clrf EEADR

You have found some generic instructions for ADC You just need one file. and 10-bit resolution
 
Last edited:
I was thinking of making it 10v hence the conversion. It can go as low as 8v before Sulphation starts.
I do have a desulphation charger though.
The 10v I thought was reasonable for a 25 minute run time. I want to suck all the current out of it but couldn't see the voltage dropping below that.
I thought I was talking about supply voltage cut off

I am getting an error testing the code
(0x10) on GPIO can not be stimulated due to being controlled by the A/D converter
Does this mean there is something wrong with the gpio initialization?
 
Last edited:
You have to work out if you want right or left justified.
You have to create an output that reads each bit in "A_Dvalue" and see what value the A/D converter has produced when the supply voltage is 10v. To do this, add a LED and 270R to pin 6 and make one LED "0" and the other "1" Bit test each bit in the file and output with a delay to read the file.
The A/D instructions have been added
 

Attachments

  • SimpleTimer-2.asm
    7.4 KB · Views: 115
Last edited:
You have to work out if you want right or left justified.
I don't have a preference or are you saying only one way will work and not the other?
You have to create an output that reads each bit in "A_Dvalue" and see what value the A/D converter has produced when the supply voltage is 10v. To do this, add a LED and 270R to pin 6 and make one LED "0" and the other "1" Bit test each bit in the file and output with a delay to read the file.
Slightly confused about how to do this. I add another led right and use the existing one as well?
 
The AD comes as 10 bits and you ahve to eliminate the top two or the bottom 2. If you eliminate the top two you can only read the lower about 50%. This is right justified.

Use the two LEDs one to indicate "0" and the other for "1" rrf A_Dvalue and bit test 0 and blink the appropriate LED.

When the battery voltage is 10v, what is the voltage detected by the A/D?
**broken link removed**
 
Last edited:
I will have to build the circuit. I am waiting for some reed switches and relay so I will build it for now with buttons instead and the second led to represent the load as you have suggested.
Will get back to you once I have done it.
I also do not have icsp, I just plug the chip into my pickit2 presently so I will need to wire up a header on the circuit also to see the voltage. Or else if it writes it correctly to EEPROM I may be able to connect the voltage and then remove the chip and read the EEPROM to determine the value
 
Last edited:
Okay, I have built the circuit now. I activated it by turning it on and off a few times.
Each time I turned it off and on again the flash led incremented and flashed 1 time more than last.
I am using a momentary button as switch a and a latching one as switch b because its all I had in the toolbox.(which I am pressing on then off again)
I have tested them for continuity so I know they are wired up correctly. I may be having some debouncing issues with switch a as it doesn't always show an action.
Switch b doesn't seem to actually do anything.
Can you run through how it is set up for me?
Looking at the code it seems like you have set sw a as the on time so it sets the amount of time the relay will be open for and flashes the led the same number of times.
Sw b is off time and seems to flash the led as well so how is that set?
Originally I was after switch b to activate the on timer when pushed and also cancel the process and sw a to set the timer and the flashes to be a part of the sw a so they flashed after each press, however the way you have written it is slightly different to that isn't it so can you run me through the setting process please.
Also, is there still a 1 minute timer after activation to get the thing to the waters edge when sw b is pressed to activate the timers?
 
Okay, so I think the circuit is not quite right. I measured from just after the output to ground and I was getting 9 volts.
I am sure I have oriented the regulator the right way. I have included 2 photos of the circuit breadboarded. Can you see anything wrong with it?
P1030072.JPG
P1030074.JPG
Thanks
Better sort that out before moving on.
I dont have a variable power supply(been intending to make one for a while) so I used a dc power pack with a 9v output so clearly nothing is getting limited at the regulator at all.
EDIT. I see what I am doing now. I have conencted both pins of the regulator to the power rail. Will sort that out now.
All sorted now. Measuring 4.9v after the output.

Steve
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top