Do the RB0 test before using others.
BTW, i'm about setting up a board to do something like this for testing. ì'll post the code here.
Do the RB0 test before using others.
BTW, i'm about setting up a board to do something like this for testing. ì'll post the code here.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
This one use RB0 interrupt handler routine.
Code:' INT0 with PWM ' ============= ' ' File name : INT0_PWM.bas ' Company : Mister E ' Programmer : Steve Monfette ' Date : 02/03/2005 ' Device : PIC18F2320 ' ' ' This program generate 3.6Khz @ 25% duty PWM on CCP1 pin. ' ' CCP1 pin is connected to RB0 pin via 1k resistor. ' ' Program blink a led on PORTB.6 while generating PWM. ' Each rising edge of PWM, PORTB.7 is toggle. This will ' generate 1.8Khz 50% duty on this PORTB.7 pin. ' ' We will use Interrupt on RB0(INT0) pin to detect rising edge ' Hardware Definition ' =================== ' DEFINE LOADER_USED 1 DEFINE OSC 20 TRISB=%00000001 ' PORTB.0 as input TRISC.2=0 ' PORTC as output ADCON1=$0F ' disable A/D converter ' Interrupt definition ' ==================== ' INTCON=%10010000 ' Enable global interrupt ' Enable INT0 interrupt (RB0) INTCON2.6=1 ' Enable INT0 on rising edge ON interrupt goto RB0_interrupt ' Variable definition ' =================== ' Tmr2dutyvar VAR WORD DelayLoop var word ' PWM signal generation ' ===================== ' Tmr2dutyvar=86 ' load duty time duration PR2=$57 ' load frequency period (PWM freq=3.6 KHZ) ' set Duty cycle ' -------------- ' CCP1CON.5=Tmr2dutyvar.1 CCP1CON.4=Tmr2dutyvar.0 CCPR1L =(tmr2dutyvar>>2) T2CON=%00000110 ' start timer 2 ' set prescaler = 16 CCP1CON = %00001100 ' pwm mode for CCP1 ' Main Loop ' ========= ' ' Stupid led blink on PORTB.6... ' Start: toggle PORTB.6 for delayloop = 1 to 50000 pauseus 5 next goto start ' Interrupt routine ' ================= ' ' toggle PORTB.6 each rising edge on it. ' disable RB0_interrupt: toggle PORTB.7 INTCON.1=0 ' reset INT0 interrupt flag resume enable
Last edited by mister_e; - 3rd March 2005 at 04:32.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
By polling INT0 flag bit... no interrupt handler
Code:' INT0 polling with PWM ' ===================== ' ' File name : INT0_poll_PWM.bas ' Company : Mister E ' Programmer : Steve Monfette ' Date : 02/03/2005 ' Device : PIC18F2320 ' ' ' This program generate 3.6Khz @ 25% duty PWM on CCP1 pin. ' ' CCP1 pin is connected to RB0 pin via 1k resistor. ' ' Program blink a led on PORTB.6 while generating PWM. ' Each rising edge of PWM, PORTB.7 is toggle. This will ' generate 1.8Khz 50% duty on this PORTB.7 pin. ' ' We will check INTCON.1 (Interrupt on RB0(INT0) flag bit) pin to ' detect rising edge ' Hardware Definition ' =================== ' DEFINE LOADER_USED 1 DEFINE OSC 20 TRISB=%00000001 ' PORTB.0 as input TRISC.2=0 ' PORTC as output ADCON1=$0F ' disable A/D converter ' Interrupt definition ' ==================== ' INTCON=%00010000 ' Disable global interrupts ' Enable INT0 interrupt (RB0) INTCON2.6=1 ' Enable INT0 on rising edge ' Variable definition ' =================== ' Tmr2dutyvar VAR WORD DelayLoop var word ' PWM signal generation ' ===================== ' Tmr2dutyvar=86 ' load duty time duration PR2=$57 ' load frequency period (PWM freq=3.6 KHZ) ' set Duty cycle ' -------------- ' CCP1CON.5=Tmr2dutyvar.1 CCP1CON.4=Tmr2dutyvar.0 CCPR1L =(tmr2dutyvar>>2) T2CON=%00000110 ' start timer 2 ' set prescaler = 16 CCP1CON = %00001100 ' pwm mode for CCP1 ' Main Loop ' ========= ' ' Stupid led blink on PORTB.6 while testing INT0 flag bit ' Start: toggle PORTB.6 for delayloop = 1 to 50000 pauseus 5 if INTCON.1 then INTCON.1=0 toggle PORTB.7 endif next goto start
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Is there any reason why I can't get the process to start when PORTA.2 goes high?? I haven't rewired the HPWM/RB0 yet, but that should not matter. The PIC should at least shift the vertical clocks before even checking the reset (interrupt flag). Are my registers set correctly for analog input to PORTA.0 and digital input to PORTA.2??
to have analog on PORTA.0
ADCON1=%00001110
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
OK, well I think I got it working so that it waits for the push button to start, but then it seems like it keeps going even after the loops have completed. I will put in an LED command to signal when clocking is in progress and see what happens. It may just be that my calculations for transfer times are just off. I figured that at 3.6Khz sampling (which is how fast we would be sampling the real data), we could sample the data, do the A/D, and send the data off chip in about 2 minutes at 19200 inverted baud. Am I off in my estimations?
Again, I have about 350,000 samples to take and transfer off the PIC serially.
Bookmarks