Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'Timer Test V1.0 Camerart 12.02.14
'Uses 12f683, internal 4mHz clock
'Define SIMULATION_WAITMS_VALUE = 1 'SIMULATION ONLY
Define CONF_WORD = %11001111000100 '0x33c4
Dim an0 As Word 'setting an0 as WORD length makes ADC count =1023 max
Dim an1 As Word 'if set as BYTE length makes ADC count =255 max
Dim t As Word 't = Ticks counter, incremented on INTERRUPT
Dim firstpulse As Byte 'Check Byte or word
Dim secondpulse As Byte
Symbol rled = GP2 'LED's
Symbol gled = GP5
OSCCON = %01100000 'Internal 4MHz osc
CMCON0 = %00000111 '7 'Comparators off
WPU = 0 'Internal pull-ups = off
OPTION_REG = %10000000 'Pull ups, TMR0, Prescaler
INTCON = %10000000 'Timer interrupt bits
ANSEL = %01000011 '0x03 '0-3 Selecting pins Analogue Digital 6 Fosc/4
ADCON0 = %00000101 'A/D 0x85?
'[in theory ALL these should start up as '0' at power ON
'but its wise to ensure that they are!]
PIE1 = 0 'peripheral intr disable
INTCON.INTE = 0
INTCON.T0IF = 0
PIE1.TMR1IE = 0 'Disable Timer 1 Overflow Interrupt
PIR1.TMR1IF = 0 'Clear Timer 1 Overflow Interrupt Flag
'set I/O pin direction
'(TRISIO = %XX001011) [ list pins in same order as binary bits]
TRISIO.5 = 0 'PIN 5 as gled
TRISIO.4 = 0 'PIN 4 unused
TRISIO.3 = 1 'PIN 5 as Button input (IN ONLY)
TRISIO.2 = 0 'PIN 5 as rled
TRISIO.1 = 1 'PIN 6 as analog1
TRISIO.0 = 1 'PIN 7 as analog0
'START UP FLASH Red then Gn LED
rled = 1
WaitMs 1000
rled = 0
WaitMs 1000
gled = 1
WaitMs 1000
gled = 0
WaitMs 1000
'preload tmr1 0.5sec count
TMR1L = %11011100 'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
TMR1H = %00001011 '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec
T1CON = %00110001 'prescale 8:1, internal clock, start tmr1
PIE1.TMR1IE = 1 'all start up done so Enable Timer 1 Interrupt
loop:
Adcin 0, an0 'read ADC0 Sets first pulse
Adcin 1, an1 'read ADC1 Sets second pulse
If an0 >= 100 Then 'if ADC0 counter => 100 then......
rled = 1 'ON IN SIMULATOR = OFF
firstpulse = an0
WaitMs an0 'this pulse duration is an0 millisec long
firstpulse = 0
Else
rled = 0 'OFF IN SIMULATOR = ON
Endif
If an1 >= 100 Then
gled = 1 'ON IN SIMULATOR = OFF
secondpulse = an1
WaitMs an1
secondpulse = 0
Else
gled = 0 'OFF IN SIMULATOR = ON
Endif
Goto loop
End
On Interrupt
Save System
'on this test the ISR is only a dummy call
PIR1.TMR1IF = 0 'must clear tmr1 intr
'must reload tmr1 0.5sec count
TMR1L = %11011100 'L + H = decimal 65536-62500=3036] = 8uSec*62500 = 0.5Sec==Count up from 3036 decimal To 65536
TMR1H = %00001011 '='Then roll over To 0000 Count And generate an Interrupt every 0.5sec
Resume
hi camerart,
This works OK, in a 12F683 I have purchased.
The LED associated with the ADC input lights when when the Vadc > 0.3V [ 100 counts] and goes dark when less than 100 ADC counts.
Please modify this code listing to include the extra commands/functions that are causing problems. post it and I will continue debugging.
Eric
hi,
Are you able to post the program code you want me to test in a PIC.?
Eric
EDIT:
In the code I have posted , tested in a PIC, the two LED's do not interact at all, they work as expected,
No flashing On and Off, just Steady when they are > 100
hi,
To double check, I have added the TMR1 interrupt to the program I posted to you, it works OK.
To show it working I have added a Blue LED on GP4 to see it flash On/Off at 0.5secs,,, its all working as I would expect, no interaction between the LED's.
Could you post a photo of your layout so that I can check its OK.?
Eric
I'm not sure I can justify the expense of your programming system, but I'll keep it in mind.hi,
I use the PICStart+.
Import the Oshonsoft hex file into MPLAB IDE, ensure that the Configuration Bits are set correctly in MPLAB
Select the PICStart prommer in the MPLAB, Enable the Prommer then Program, wait until successful message.
What method do you you use.?
When I pick up your 12F683 tomorrow are they already programmed with your system.?
E
Hi Eric,hi
I will preprogram the 2 I send back to you
hi,
In case you have a corrupted copy of the program, its here as an attachment.
E