28x2 Internal Timer Display on AXE134y

Lt2mc

Member
First time post, long time player. I have been playing with the Picaxe for several years, and this project has finally stumped me. I am working on a project to monitor LED life spans at various power settings, all the control functions have been straight forward, however the "elapsed" timer function is proving troublesome. Under simulation my timer sequence works as it should. However when I tie the system to the hardware, I cannot get the OLED to update the displayed elapsed time, other variables and signals work fine.
OLED_Display1.jpg
I am using a 28x2 and axe134y, and some of my research seems to indicate I may have a serout or interrupt conflict between the two MCs, which is beyond my current skills. Does anyone have some suggestions on what i may be missing?? Not to be presumptuous, but before someone asks, I will post the code I am currently working with. Thanks in advance.
BTW, Please feel free to critique my code formatting, I am a hardware guy by trade and all my SW experience is by hack. :unsure:
Code:
;Integrate timer sequance
;
;Uses 28x2,
;
;Symbols

Let dirsA = %10111            ;A0,A1,A2,A4 =Outputs
Let dirsB = %11100000            ;B7,B6,B5 =Outputs
Let dirsC = %01011110            ;C6,C4,C3,C2,C1 =Outputs
DACsetup %10101000            ;Sets up pin4 to analog out
fvrsetup fvr1024                ;Max ref voltage
Let w6 =4                    ;LED 50%
Let w5 =4                    ;Base value
Let b2 =0                    ;Clear all signals out to track
pullup %00011111                ;enable pullups on portB0-4 on 28X2


Begin:     ;LED Unit power up
    Pause 1000
    serout A.4,N2400,(254,212,"LED Use             ");Line2 Display saved use time
    pause 1000
    serout A.4,N2400,(254,148,"LED Type DUV4a-2a    ");Line3, icRev-oledRev
    pause 1000
    Pause 2000
    let pinB.5 =0                        ;clears previous lamp ON command
    let pinC.4 =0                        ;clears previous lamp ON to track
    let pinC.3 =0                        ;clears previous lamp RDY to track
        
LEDP: ;LED light power sequance, sets initial power and normal operations
    ;Temp check sequance
        readtemp C.5, B1                        ; Read the DS18B20 temperature
        pause 10                            ; Wait a while
        serout A.4,N2400,(254,148,"   LED Temp = ",#B1,"c    ");Text on 2nd line
        If B1>40 then
        serout A.4,N2400,(254,148,"LED is at Over-Temp ");Text on 2nd line
        let pinC.6 =0                        ;LED OVT error to track
        else let pinC.6=1
        endif
    ;Manual Operation
        if pinB.2 =1 then                        ;checks for filter signal from track
        let pinC.1 =1                        ;filter active to track
        else
        let pinC.1=0                        ;Filter not active to track
        end if
        if pinB.1 =0 then
        let pinC.2 =1                         ;Shutter active to track
        else
        let pinC.2 =0                        ;Shutter not active to track
        let pinC.2=0
        end if
    ;Lamp on
        If pinB.0 =0 then                        ;lamp on comand from track NEEDS A FLAG?
        Pause 20                            ;Wait lamp to turn on
        let pinC.4 =1                        ;lamp ON simulated confirm to track
        Pause 20                            ;wait lamp to warm up
        let pinC.3 =1                        ;lamp RDY simulated confirm to track
        let w7=w6/1
        serout A.4,N2400,(254,192,"LED Power = ",#w7,"mJ  ");Displays current LED pwr setting line2
        else
        let pinC.4=0                        ;lamp is not ON to the track
        let pinC.3=0                        ;lamp not RDY to track
        goto LEDP
        end if
    ;Timer Sequance
        serout A.4,N2400,(254,212,"LED Use: ", #W12 ," Hrs ", #w11 ," min");Real time display line2   
        if pinB.1 =0 then   
        settimer t1s_4                ;Timer counts at 4mhz
        ;TMR3SETUP %00110011            ;1:8 prescale, on
        ;let w10=timer3
            let w10=timer
        end if
        if pinB.1 =1 then
        ;Tmr3SETUP %00110010            ;1:8 prescale, off
        settimer off
        let timer=0
        end if
        if w10>59 then        ;Elapsed Seconds
            let w11=w11+1
            let w10=0
            let timer=0
        end if
        if w11>59 then         ;Elapsed Minutes
            let w12=w12+1    ;Elapsed Hours
            let w11=0
        end if
        
    ;Normal operation
        If pinB.1 =0 and pinB.0 =0 then            ;Shutter open and lamp ON comand
        daclevel w6                            ;Lamp on to set analog out level
        serout A.4,N2400,(254,192,"LED Power = ",#w7,"mJ  ")    ;Displays current LED pwr setting line2
        serout A.4,N2400,(254,128,"  LED is Radiating     ")    ;LED is ON line1
        let pinC.2 =1                        ;shutter not blocking to track
        endif
        if pinB.1 =1 then                        ;No shutter open comm from track
        daclevel 0                            ;No analog signal out to lamp   
        serout A.4,N2400,(254,128,"LED is Not Radiating")    ;LED is OFF line1
        let pinC.2 =0                        ;shutter blocking to track
        endif
        if pinB.0 =1 then                        ;No lamp ON comm from track
        daclevel 0                            ;No analog signal out to lamp
        serout A.4,N2400,(254,128,"LED is Not Radiating")    ;LED is OFF line1
        let pinC.2 =0                        ;shutter blocking
        let pinC.3 =0                        ;Lamp not ready
        goto LEDP
        endif   
        if pinB.4 =1 and pinB.1 =0 and pinB.0 =0 then    ;Inc ON, Shutter OPEN, and Lamp on
        gosub PWRINC                        ;Power increase sub routine
        end if
        if pinB.3 =1 and pinB.1 =0 and pinB.0 =0 then    ;DEC ON, Shutter OPEN, and Lamp on
        gosub PWRDEC                        ;Power decrease sub routine
        end if
        ;write 16,b10,b11                        ;write saved power to manipulated power
        if pinB.2 =1 and pinB.1 =0 and pinB.0 =0 and w6>w4 then    ;Filter IN, Shutter open,lamp ON
        gosub Filtr                            ;Filter sub routine
        endif
        if pinB.2 =0 and w6<w5 then
        gosub FiltrOFF                            ;Saves adjusted value W6 to Main saved W5
        end if
        ;let w5=w6
        goto LEDP
            
    PWRINC:
    if w5<31 then                ;Track increases LED pwr 32max
    let w6=w5+1
    let w5=w6
    endif
    write 16,b12,b13
    if w5>31 then                ;Track increases LED pwr
    serout A.4,N2400,(254,192,"LED Power is at max ");Displays max power warning line2
    endif
    return
    
    PWRDEC:
    if w5>2 then                ;Track decreases LED pwr 2 min
    let w6=w5-1
    let w5=w6
    endif
    write 16,b12,b13
    ;write 16,b10,b11   
    if w5<2 then                ;Track decreases LED pwr
    serout A.4,N2400,(254,192,"LED Power is at min ");Displays min power warning line2
    endif
    return

    Filtr:                            ;Filter in sequance
    ;serout A.4,N2400,(254,212," Filter is active   ");Displays filter status line4
    let pinC.1 =1                        ;filter active to track
    if b3 bit 0 clear then
    let w4=w5/2                            ;cut power by50%
    let w6=w4                             ;send cut power to pwm value
    setbit b3,0                            ;sets power filtered bit
    endif
    return
    FiltrOFF:
    ;serout A.4,N2400,(254,212,"Filter is not active");Displays filter status line4
    let pinC.1=0                        ;Filter not active to track
    clearbit b3,0                        ;clears power filtered bit
    let w6=w5
    ;write 16,b12,b13                        ;Saves adjusted value w6 to EPROM
    return
 

inglewoodpete

Senior Member
Welcome to the PICAXE forum.

Well done for getting this far with your project. It is quite well commented, so it makes it so much easier for forum members to read and understand its function.

Firstly, the default speed for the 28X2 is 8MHz, so defining the clock tick as "t1s_4" will cause timer1 to tick every half second. Use the constant "t1s_8" for accurate 1-second timing.

I can't find a fault in your timer code when I had a quick read of it. If it is possible to run the program in the real hardware while connected to your computer via the programming cable, you could add some temporary logging code to help you determine what is going on.

Add the command SerTxd(#w12, ":", #w11, ":", #w10, CR, LF) just after your "Let w10 = timer" command in the section titled ";Timer sequence". Also, add the directive "#terminal 9600" at the top of your program. The #terminal directive will cause the programming editor's terminal emulator program to open, allowing SerTxd command outputs to be viewed.
 

bfgstew

Senior Member
Under your section 'timer sequance' remove the 3 after
;let w10=timer3
and as Pete mentioned change tls_4 to tls_8.
hope this helps?
Stewart
 

Aries

New Member
I'm not sure - I don't have a Picaxe handy to check - but I suspect that a settimer instruction resets timer to zero. If so, your "Timer Sequance" is resetting the timer every time, so it may never get to count.
 

bfgstew

Senior Member
In simulation on PE6, w10 doesn't count anything with timer3, with it as just timer it counts?
 

Lt2mc

Member
Thanks for all the great input. I have corrected my clock time to t1s_8, unfortunately I cannot tap into the ic when it is interfaced to the hardware. So far today, after numerous cups of coffee and a few beers, here is where I stand. It looks like it may have been zeroing the timer (Thanks Aries) and there may have been a timing problem with the prog updating the serout. I added a few pauses and I was able to get some feedback, though sporadic. To keep the code efficient, I am now taking the direction of displaying real-time dose (seconds) data, then calculating usage hrs:min:sec after the LED is off, and displaying that until the LED comes back on. I hope I can do all that using an eeprom read/write function. Stay tuned....
 
Top