News:

;) This forum is the property of Proton software developers

Main Menu

Need very simple IOC sample on 12F683

Started by Maxi, Mar 23, 2021, 09:03 AM

Previous topic - Next topic

Maxi

Hi, I need a very simple working example
I dont understand IOC mechanism

Use GPIO.0 input with IOC interrupt and timer1 interrupt for measure under 100hz frequency

edit:
I can make this easly GP2/int external interrupt (pin5)
but I need to use hpwm,
so CCP1 (pin5) save for hpwm must be empty

m.kaviani

What do you want to do. please explain more.

top204

#2
There is no PIC12F628 device? Is it a PIC12F629 or 12F675?

Also... What frequency is the microcontroller operating at? This is a very important criteria for counting pulses with a set window, because a timer has to be setup based upon the microcontroller's fOsc?

Maxi


Maxi

Quote from: m.kaviani on Mar 23, 2021, 09:43 AMWhat do you want to do. please explain more.

ok, I want to read 10hz-100hz frequency from GPIO.0 (pin7)

FiremanTR

The best thing I know is that I know nothing
__SOCRATES__

m.kaviani

I used the PULSEIN command that can read a pulse period from 1 to 65535 units. I used it to read a remote control IR receiver and
it works fine.
the micro was 12F675 with a 20MHz internal oscillator. the Samsung was 2.25 ms.

proton manual:
(The units are dependant on the frequency of the crystal used. If a 4MHz crystal is used, then
each unit is 10us, while a 20MHz crystal produces a unit length of 2us.)

FiremanTR

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 12F683

Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, CPD_OFF, BOREN_ON, IESO_ON, FCMEN_ON
'Config FCMEN_OFF,IESO_OFF,BOD_ON,CPD_OFF,CP_ON,MCLRE_OFF,PWRTE_ON,WDT_OFF,INTRC_OSC_NOCLKOUT

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Xtal 8
'OSCCON =%01110000
OSCCON = %01110001   
Declare All_Digital TRUE

TRISIO =%00000001
GPIO =0

ANSEL =0
OPTION_REG =%11000000
ADCON0 =0
CMCON0=7
WPUA =0

Symbol PEIE = INTCON.6 ' Peripheral Interrupt Enable
Symbol GIE = INTCON.7  ' Global Interrupt Enable
Symbol GPIE =INTCON.3
Symbol GPIF =INTCON.0
Symbol TMR1IF =PIR1.0
Symbol TMR1IE =PIE1.0
Symbol IOC0 =IOC.0

GIE =0
PEIE =1
TMR1IE =1
GPIF =0
GPIE =1
TMR1IF =0
IOC0 =1

On_Hardware_Interrupt GoTo Kesme

Include "Shift_Print.inc"           ' Load the LCD Shift Print library routine into the program

$define LCD_Pin GPIO.1                 ' Set the pin to use for the communication with the 74595 shift register


Dim MyCounter As Byte
Dim Count As Word
Dim myFreq As Word
Dim  TenMs As Word

 TenMs =45543  'for ten mS  timer1 preload


Print At 1,1,"FREQ:"
DelayMS 100
T1CON. =%00000001
GIE=1

MaIn:
Print At 1,6,Dec myFreq," Hz "
DelayMS 400

GoTo MaIn



 Kesme:
 Context Save
 If GPIF =1 Then
   Count =Count +1
    Toggle GPIO.2
     GPIF =0
 EndIf
 If TMR1IF =1 Then
     Inc MyCounter
     If MyCounter >=50 Then
         myFreq =Count
         MyCounter =0
         Count =0
     EndIf
     TMR1L =TenMs.LowByte
     TMR1H =TenMs.HighByte
     TMR1IF =0
EndIf
 
 Context Restore
 End



I did it with interrupt. I turned on 10 mS timer1, activated IOC0 and counted. running in the background
The best thing I know is that I know nothing
__SOCRATES__

top204

I've created a Proton8 program to count low to mid frequencies using a PIC12F683 device, using a Timer0 interrupt for the capture window, and Timer1 for the pulse counter, so it all operates in the background.

It can be found here:
Low to Mid frequency measurement on a PIC12F683 device

I hope you find it useful.