Jump to content

dknovick

EstablishedMember
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

0 Neutral

About dknovick

  • Rank
    Newbrie

Contact Methods

  • Website URL
    http://
  • ICQ
    0
  • Yahoo
    dknovick

Profile Information

  • Location
    Albuquerque, NM
  1. Just downloaded the latest MPLAB X IDE v1.00. Looks like the official release has changed a few things, and they are expecting one toolchair per Base directory (unless I'm doing something wrong)
  2. In that case, I'll definitely look into it. I still do some things old-school.
  3. I guess I answered my own question, the code seems to work in hardware. I blink an LED after the while loop... and, well, the LED blinks. Next up, hooking a pot to the input to see if I can turn the LED on at a certain voltage.
  4. Haven't had the time to dig into serial stuff yet (that's next).
  5. Maybe this will help us both out. I'm using a PIC16F88 to read in an A/D value. I have it set up to use the RC oscillator (INTRC) so that it runs as 31.25 kHz (I need to use it as a nanoWatt device). Here's my small bit of code: #include <system.h> #pragma DATA _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_ON & _BODEN_ON & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_CLKOUT #pragma DATA _CONFIG2, _IESO_ON & _FCMEN_ON // Set 20MHz clock frequency #define CLOCK 31250 #pragma CLOCK_FREQ CLOCK #define ON 0 #define OFF 1 // Globals volatile bit adc_on @ADCON0.ADON; // A/D conversion on bit volatile bit adc_go @ADCON0.GO; // A/D conversion status bit void main() { unsigned char wait; long analog; // Set up the Analog selection register ansel = 0x01; // 1=Analog, 0=Digital RA0 as analog trisa = 0x01; // 1=input, 0=output RA0 as input (for analog) // Set up A/D Control Register 1 set_bit( adcon1, ADFM ); // A/D right justified clear_bit( adcon1, ADCS2 ); // A/D clock /2 clear_bit( adcon1, VCFG1 ); // set to use AVdd AVss clear_bit( adcon1, VCFG0 ); // Set up A/D Control Register 0 set_bit( adcon0, ADCS1 ); // Tad = Frc derived from the internal A/D RC oscillator set_bit( adcon0, ADCS0 ); clear_bit( adcon0, CHS2 ); // Channel 0 clear_bit( adcon0, CHS1 ); clear_bit( adcon0, CHS0 ); trisb = 0x00; // 1=input, 0=output wait = 10; while( 1 ) { adc_on = 1; // Turn on the A/D converter delay_ms( 1 ); adc_go = 1; // Start the conversion of ch0 while( adc_go ) // wait for it to finish ; MAKESHORT( analog, adresl, adresh ); // Grab the A/D conversion adc_on = 0; // Turn off the A/D converter delay_ms( wait ); } } However, when I try to debug it with the Variable PSU attached to RA0, it never breaks out of the while() loop
  6. Ahhh yes, that did it! page 153 for the 'A'. I hadn't looked at that part of the manual. Thanks!
  7. You are right! page 153 for the 'A'. I hadn't made it that far into the manual. I dug through the timer 0 and timer 1 descriptions. And now it just does! Thanks!
  8. I'm using a PIC 16F876A Is there only one interrupt service routine (ISR)? void interrupt( void ) I ask, because I'm trying to use timer1 to set the duty cycle and frequency of a output, and while that works, I have to have timer0 running in order for the ISR to be called. Stepping through the program, I can watch TMR1 increment and on overflow it sets TMR1IF of the PIR1 register. However interrupt() isn't called until TMR0 rolls over. Maybe I'm doing something wrong? Here's my code: #include <system.h> #pragma DATA _CONFIG, _CP_OFF & _DEBUG_OFF & _WRT_OFF & _CPD_OFF & _LVP_ON & _BODEN_ON & _PWRTE_OFF & _WDT_OFF & _HS_OSC // Set 20MHz clock frequency #define CLOCK 20000000 #pragma CLOCK_FREQ CLOCK // // Globals // unsigned short f, N, t_dwell; unsigned short T, t1, t2; unsigned char Duty; // // Functions // void interrupt( void ) { unsigned short cyc; if( test_bit(intcon, TMR0IF) ) { //portb.0 = !portb.0; clear_bit( intcon, TMR0IF ); } if ( test_bit( pir1, TMR1IF) ) { portb.0 = !portb.0; if ( portb.0 ) { cyc = t1; porta.0 = !porta.0; } else cyc = t2; clear_bit( t1con, TMR1ON ); HIBYTE( tmr1h, cyc ); LOBYTE( tmr1l, cyc ); set_bit( t1con, TMR1ON ); clear_bit( pir1, TMR1IF ); } } void setTimes( void ) { unsigned short t = T/100; // 2^16-1 = 65535 t1 = 65535 - t*Duty; t2 = 65535 - t*(100-Duty); } void main() { adcon1 = 0x06; // Set RA0-5 as D I/O trisa = 0x00; // 0 = output, 1 = input porta = 0; trisb = 0; // outputs portb = 0; // clear 'em // Timer 0 clear_bit( option_reg, T0CS ); // T0 internal clear_bit( option_reg, T0SE ); // T0 low-to-high set_bit( option_reg, PSA ); // Prescaler assigned to WDT // Timer 1 clear_bit( t1con, T1CKPS1 ); // 1:1 prescaler clear_bit( t1con, T1CKPS0 ); clear_bit( t1con, T1OSCEN ); // T1 oscillator off set_bit( t1con, NOT_T1SYNC ); // Do Not synchronize external clock input clear_bit( t1con, TMR1CS ); // Internal clock set_bit( pir1, TMR1IF ); set_bit( t1con, TMR1ON ); // T1 enabled Duty = 60; f = 2500; T = CLOCK/(4*f); setTimes(); // Enable interrupts set_bit( intcon, TMR0IE ); set_bit( pie1, TMR1IE ); set_bit( intcon, GIE ); while( 1 ) ; }
×
×
  • Create New...