Jump to content

Johan Matthee

EstablishedMember
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Johan Matthee

  • Rank
    Newbrie
  1. Dave Thanks for the promp answer, I saved the web page for future reference and will use the 16F877 for simulation in the future. Regards Johan
  2. I am trying to simulate the ADC function on a PIC16F819 by connecting the Variable PSU of the extended plugin to inputs on PORTA. I see change on the port, but no response from the ADC. I there some special way to do it or only one way to do it. If I can't use the device mentioned, which devices can I try that will work. Thanks Johan
  3. Hi I can write code to get TMR0 Interrrupt to control my Real Time Clock. Use Hardware or Software Interrupts to call Functions to execute the all the code needed to control my program. What I can't do is call a Function to do an A/D conversion without setting bit ADIE in Register PIE1. When bit ADIE is set, the ADC Function works flawlessly exept that I lose my TMR0 capabillity. My finding was that both TMR0 interrupt and A/D Conversion work exellent but I can't get them to work together. I do need help here! #include <p12f675.h> // Global variables declaration char INTCNT = 244;//Aproximate count for one sec char SECADJ = 7; //correction for one sec char ADH; //Storage for A/D converter High bite char ADL; //Storage for A/D converter LOW bite char Index = 3; //future use char Pulse = 0; //future use //Configuration bits asm { list p=12F675 __config H'318C' } void on_init(void) { // initialize peripherals and the application option_reg = 3; //set prescaler to 1:16 (4.096mS) enable_interrupt( GIE ); //enable global interrupts set_bit( intcon, T0IE );//set TMR0 interrupt //set_bit(pie1, ADIE); //enable A/D converter interrupt set_bit( intcon, PEIE ); //all unmasked interrupts trisio = 0x0B; //GP:0,1&3 inputs. GP:2,4&5 outputs ansel = 0x13; //AN0-PIN7 & AN1-PIN6 Analog inputs and 8Tosc selected cmcon = 7; // No comparator selected gpio = 0; //all outputs to zero ADH = adresh; //address high ADL = adresl; //address low } //List of all functions void on_init(void); //sets up interrupts, ports, pins etc. void on_adc(void); //A/D conversion void interrupt( void ) { //generate 1 sec pulse INTCNT--; if( INTCNT == 0 ){ INTCNT = 244; //reset count SECADJ--; //dec SECADJ every second gpio ^= 0x04; //compliment GPIO:2 (LED ON/OFF) } if( SECADJ == 0 ) { //time to add correction INTCNT ++; //add correction to 1 sec SECADJ = 7; //reset FUDGE } clear_bit( intcon, T0IF ); //clear TMR0 bit T0IF on_adc(); //take new reading at ADC } void on_adc(void) { clear_bit( pir1, ADIF ); adcon0 = 0x01;//Left justified, Vdd, GO_DONE = 0, ADON delay_us( 50 ); //small delay set_bit( adcon0, GO );//start A/D Converter if (( ADH >= 0 )&&( ADH <= 5 )) { //220V - 215V set_bit( gpio, GPIO5 ); } if (( ADH >= 6 )&&( ADH <= 10 )) { //214V - 210V set_bit( gpio, GPIO4 ); } if (( ADH >= 11 )&&( ADH <= 15 )) { //209V - 205V set_bit( gpio, GPIO5 ); } if (( ADH >= 16 )&&( ADH <= 20 )) { //204V - 200V set_bit( gpio, GPIO4 ); } if (( ADH >= 21 )&&( ADH <= 25 )) { //199V - 195V set_bit( gpio, GPIO5 ); } if (( ADH >= 26 )&&( ADH <= 30 )) { //194V - 190V set_bit( gpio, GPIO4 ); } if (( ADH >= 31 )&&( ADH <= 35 )) { //189V - 185V set_bit( gpio, GPIO5 ); } if (( ADH >= 36 )&&( ADH <= 40 )) { //184V - 180V set_bit( gpio, GPIO4 ); } if (( ADH >= 41 )&&( ADH <= 255 )) { //Less then 180V set_bit( gpio, GPIO5 ); } } main() { on_init(); // do initialization once while(1) //endless loop { clear_wdt(); //reset Watchdog timer } }
×
×
  • Create New...