Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[General] Dimmer with PIC16F877A

chrisss

Newbie
Newbie level 1
Joined
Nov 21, 2024
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
Missing CODE/SYNTAX tags ( Added by moderator )
Hello, I’m trying to make a dimmer with the PIC16F877A. I found some code and a circuit that I’m testing to use later.
However, I’m encountering several problems. When I start my simulation, the following message appears:

[PIC16 MEMORY] PC=0x0A69. Attempt to write unimplemented memory location 0x008F with 0x71 ignored. [U1].

I’m not sure what the error could be.
Here’s the code I’m using, along with images of my simulation and circuit. code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**************************************************************************************
 AC Lamp light dimmer with PIC16F877A microcontroller
 C Code for CCS C compiler
 Crystal oscillator used @ 20MHz
 This is a free software with NO WARRANTY.
 [URL]http://simple-circuit.com/[/URL]
***************************************************************************************/
#define triac_gate    PIN_D2
 
#include <16F877A.h>
#device ADC = 10
#fuses HS,NOWDT,NOPROTECT,NOLVP                     
#use delay(clock = 20MHz)
#use fast_io(d)
#byte OPTION_REG = GETENV("SFR:OPTION_REG")    // get OPTION_REG register address
#bit  INTEDG = OPTION_REG.6                    // INTEDG (external interrupt edge) bit address ( OPTION_REG(6) )
 
int1 ZC = 0;
int16 alpha;
 
#INT_EXT            // external interrupt ISR
void ext_isr(void)
{
  ZC = 1;
 
  // toggle external interrupt edge
  if(INTEDG) INTEDG = 0;
  else       INTEDG = 1;
 
}
 
void main()
{
  output_low(triac_gate);
  output_drive(triac_gate);
 
  setup_adc(ADC_CLOCK_INTERNAL);     // set ADC clock source
  setup_adc_ports(AN0);              // configure AN0 pin as analog
  set_adc_channel(0);                // select channel AN0
 
  clear_interrupt(INT_EXT);          // clear external interrupt flag bit
  enable_interrupts(GLOBAL);         // enable global interrupts
  enable_interrupts(INT_EXT);        // enable external interrupt
 
  delay_ms(500);
 
  while(TRUE)
  {
    alpha = ( 1023 - read_adc() ) * 10;
 
    if (alpha > 9500)
      alpha = 9500;
    else if (alpha < 200)
             alpha = 0;
 
    while(ZC == 0) ;    // wait for zero crossing event
 
    // send firing pulse after alpha
    delay_us(alpha);
    output_high(triac_gate);
    delay_us(200);
    output_low(triac_gate);
 
    ZC = 0;
  }
}
// End of code


Screenshot_6.jpg


pic16f877a-light-dimmer-220v-ac-bt136-triac-circuit.png
 
Last edited by a moderator:
I can't see anything obvious in the code but I'm not familiar with the quirks in CCS compilers.
You need to find out what is actually at "PC=0x0A69" by looking in the listing or map files. That should tell you which instruction is causing the error. I would guess it has something to do with memory allocation, possibly the code was written for a different processor as address 0x008F (in bank 1) isn't mapped to any pin or peripheral.

Brian.
 
As you are writing the ZC variable in the ISR but reading it in the main loop, you need to declare it volatile.
Tying \MCLR\ to +5V (in the top schematic) wil lmake it imposible to program a real device. The bottom schematic is better but check the data sheet for the recommended way to connect \MCLR\.
Susan
 

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top